Skip to content

feat(cli): distinct exit codes per failure class (#334) - #337

Merged
lxsaah merged 2 commits into
mainfrom
feat/334-cli-exit-codes
Oct 24, 2026
Merged

lxsaah merged 2 commits into
mainfrom
feat/334-cli-exit-codes

Conversation

@lxsaah

@lxsaah lxsaah commented Oct 24, 2026

Copy link
Copy Markdown
Member

Description

aimdb used to exit with 1 for every error, so a script couldn't tell an unreachable instance (worth retrying) from a refused request. Every command now uses one exit-code scheme:

Code Class
0 Success
1 Rejected: the instance or a remote service refused the request (RecordNotFound, WriteProtected, ServerError, Other)
2 Usage: clap's usage errors, UnsupportedEndpoint, InvalidJson
3 Environment: ConnectionFailed, NoInstancesFound, ProtocolMismatch, Io, Json
4+ Command-specific (e.g. join's device flow, design 056 §5)

Changes

  • CliError::exit_code() with the constants EXIT_REJECTED, EXIT_USAGE and EXIT_ENVIRONMENT. The match has no wildcard, so a new variant won't compile until its code is chosen.
  • main exits with e.exit_code().
  • Design 056 §5 now refers to this shared scheme instead of "1 for all existing variants", and step 1 of §9 is marked done.
  • The CLI README gets an "Exit codes" section, and the CLI changelog a Changed (breaking) entry: connection errors now exit with 3 instead of 1.

Tests

  • Unit test: every CliError variant maps to its class.
  • tests/exit_codes.rs runs the aimdb binary: an unreachable unix:// socket → 3, --connect bogus://x → 2, invalid JSON for record set --dry-run → 2, an unknown subcommand → 2. The first three fail when main still exits with exit(1).

Verified locally: cargo test -p aimdb-cli and cargo clippy -p aimdb-cli --all-targets. The full make check is left to CI.

Found while doing this, but not changed here: aimdb-cli doesn't compile with --features yaml. That gets its own PR.

Related Issue

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have added tests to cover my changes.
  • All new and existing tests passed (make check). Left to CI.
  • I have updated the documentation accordingly.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e

@lxsaah
lxsaah force-pushed the feat/334-cli-exit-codes branch from a9278f2 to a107544 Compare October 24, 2026 09:57
@lxsaah
lxsaah merged commit 4223d76 into main Oct 24, 2026
12 checks passed
@lxsaah
lxsaah deleted the feat/334-cli-exit-codes branch October 24, 2026 10:37
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.

[FEAT] aimdb CLI: distinct exit codes per failure class

1 participant