Add package to exit program with relevant exit code. - #1101
Conversation
This adds Exit() and LogExit(), which detect if an error is a GRPC error, context cancelled, or context deadline exceeded, and exit with the appropriate exit code. This lets us add tests to make sure that a connector exits with the correct GRPC status if it hits an auth error.
| } | ||
|
|
||
| // Otherwise, exit with code 2, which is GRPC status code Unknown. | ||
| return int(codes.Unknown) |
There was a problem hiding this comment.
🟡 Suggestion (confidence: high): This silently changes the exit code of every connector's ordinary failure path from 1 to 2, since config.RunConnector is the shared entrypoint for the whole fleet. Non-zero-ness is preserved so != 0 checks are unaffected, but anything that distinguishes specific codes (CI scripts, container orchestration, the platform task runner) will see a different value with no migration note and no pkg/sdk/version.go signal.
Separately, codes.Unknown == 2 is also the exit code the Go runtime uses for an unrecovered panic, and the conventional "usage error" code for CLIs. That makes 2 ambiguous exactly where this package is meant to be the oracle: a test asserting "exited 2 → generic error" also passes when the connector panicked.
| Exit(err) | ||
| } | ||
|
|
||
| func exitCode(err error) int { |
There was a problem hiding this comment.
🟡 Suggestion (confidence: medium): exitCode is unexported, so the only public way to learn the code for an error is to terminate the process. The PR's stated goal is asserting that connectors exit with the right gRPC status; exporting this as Code(err error) int would let downstream connectors and their tests map an error to a code without a subprocess harness, and keeps Exit/LogExit as thin wrappers.
General PR Review: Add package to exit program with relevant exit code.Blocking Issues: 0 | Suggestions: 3 | Threads Resolved: 0 Review SummaryScanned the full PR diff (4 files, +145/-8) for security and correctness: the new Risk triage (per
Consequence lands at remediation rung ~2 rather than rung 4, because every error path still exits non-zero (minimum code is Security IssuesNone found. Correctness IssuesNone found. Suggestions
Prompt for AI agents |
This adds Exit() and LogExit(), which detect if an error is a GRPC error, context cancelled, or context deadline exceeded, and exit with the appropriate exit code.
This lets us add tests to make sure that a connector exits with the correct GRPC status if it hits an auth error.
Getting this behavior requires a small change to each connector. Without it, syncs still exit with status code 1 no matter what. The print/exit behavior in main.go should be change from this:
to this: