Skip to content

fix: exit non-zero whenever a command reports an error - #60

Merged
radim10 merged 2 commits into
masterfrom
fix/cli-exit-codes
Oct 8, 2026
Merged

radim10 merged 2 commits into
masterfrom
fix/cli-exit-codes

Conversation

@radim10

@radim10 radim10 commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #59, which fixed exit codes for agent commands; 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.

  • A failed command now exits 1. A child process started by run keeps its own exit code.
  • Handlers that print their own error now return ReportedFailure, which exits 1 without printing the error twice. This covers:
    • run and pull when no secrets are found, or when the user declines to proceed after that error
    • run when fetching secrets fails
    • the config setters, which previously returned nothing
  • A missing API key in agent run is now reported to telemetry as auth, not validation. agent run skips 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.
  • The bare agent hooks invocation still exits 0 on failure, because Claude Code, Codex and Cursor read its exit code.

The one remaining early Ok(()) in run is when the user cancels the stashbase.yaml config picker, which still exits 0. It's a cancel, not an error; whether it should exit 130 can be decided separately.

Tests

  • New a_missing_api_key_in_agent_run_is_reported_as_an_auth_error in tests/telemetry_cli.rs. It fails if the fix is reverted to Validation.
  • cargo test passes (522 + 23 + 33).
  • The agent run and loopback tests need local ports, so they skip themselves inside a sandbox; I ran the suite outside one.

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(()).
@radim10 radim10 self-assigned this Oct 8, 2026
@radim10
radim10 merged commit 94b02e9 into master Oct 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant