Repository navigation
fix: exit non-zero whenever a command reports an error - #60
Merged
Merged
Conversation
Every command that printed an error still exited 0, so scripts and CI could not tell a failed pull, secrets request or config change from a successful one. A failed command now exits 1; a child process keeps its own exit code. Handlers that print their own error and used to return normally now return ReportedFailure, which exits 1 without printing the error twice: run and pull when no secrets are found (or the user declines to proceed after that error), run when fetching secrets fails, and the config setters, which returned nothing at all. The bare `agent hooks` invocation keeps exiting 0 on failure, since Claude Code, Codex and Cursor read its exit code.
`agent run` skips the root API-key guard so file-only profiles can run, and meets a missing key later, when it fetches remote secrets. That path recorded the failure as a validation error, while the root guard and the JSON output call it an authentication error. It now reports `auth`. Adds a telemetry test for that path, and corrects the handle_load_env_run doc comment, which still said its printed errors return Ok(()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #59, which fixed exit codes for
agentcommands; this applies the same fix to the rest of the CLI.Before this change, every command that printed an error still exited 0, so scripts and CI couldn't tell a failed
pull, secrets request or config change from a successful one.runkeeps its own exit code.ReportedFailure, which exits 1 without printing the error twice. This covers:runandpullwhen no secrets are found, or when the user declines to proceed after that errorrunwhen fetching secrets failsagent runis now reported to telemetry asauth, notvalidation.agent runskips the root API-key check so file-only profiles can run, and only hits the missing key when it fetches remote secrets. The root check and the JSON output already call this an authentication error.agent hooksinvocation still exits 0 on failure, because Claude Code, Codex and Cursor read its exit code.The one remaining early
Ok(())inrunis when the user cancels thestashbase.yamlconfig picker, which still exits 0. It's a cancel, not an error; whether it should exit 130 can be decided separately.Tests
a_missing_api_key_in_agent_run_is_reported_as_an_auth_errorintests/telemetry_cli.rs. It fails if the fix is reverted toValidation.cargo testpasses (522 + 23 + 33).agent runand loopback tests need local ports, so they skip themselves inside a sandbox; I ran the suite outside one.