Skip to content

feat: standardize exit codes across all CLI commands#882

Merged
BYK merged 9 commits intomainfrom
feat/standardize-exit-codes
Apr 29, 2026
Merged

feat: standardize exit codes across all CLI commands#882
BYK merged 9 commits intomainfrom
feat/standardize-exit-codes

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 29, 2026

Summary

Adds semantic exit codes to every CliError subclass so scripts, CI pipelines, and AI agents can react to failure categories without parsing stderr.

  • Adds an exported EXIT constant object to src/lib/errors.ts with 18 semantic codes
  • Wires each error class constructor to use the appropriate exit code
  • Fixes trace/view and log/view to throw ResolutionError (exit 23) instead of ValidationError (exit 21) for "not found" cases — aligning with the error hierarchy guidelines
  • Updates 43+ test assertions across unit and e2e tests
  • Adds a docs reference page at /exit-codes/ with scripting examples
  • Documents the sentry api OutputError convention (exit 60 for API errors rendered to stdout)
  • Updates agent guidance and AGENTS.md with exit code documentation

Exit Code Ranges

Range Category HTTP Analogy
0 Success 200 OK
1 General error 500 Internal
10–19 Auth & identity 401/403
20–29 Input & config 400/404/422
30–39 API & network 502/504
40–49 Feature/billing 402/451
50–59 Operations
60–69 Command-specific

Error Classification Fix

This PR also fixes two pre-existing error classification issues that would have been cemented as permanent API contracts by the new exit codes:

  • trace view: "No trace found" now throws ResolutionError (exit 23) instead of ValidationError (exit 21). A valid hex ID that doesn't match any trace is a resolution failure, not a validation failure.
  • log view: Same fix — throwNotFoundError now throws ResolutionError for logs that don't exist.

Backward Compatibility

Purely additive — exit code 1 becomes more specific (10, 20, 21, etc.). Scripts that check != 0 are unaffected.

Closes #392

Add semantic exit codes to every CliError subclass so scripts, CI
pipelines, and AI agents can react to failure categories without
parsing stderr.

Exit codes are grouped into decades inspired by HTTP status semantics:
- 1x: Auth & identity (401/403 family)
- 2x: Input & config (400/404/422 family)
- 3x: API & network (502/504 family)
- 4x: Feature/billing (402/451 family)
- 5x: Operations (upgrade, OAuth)
- 6x: Command-specific

All codes stay below 128 to avoid collision with Unix signal exits.

Closes #392
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-882/

Built to branch gh-pages at 2026-04-29 06:10 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Codecov Results 📊

6317 passed | Total: 6317 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +17
Passed Tests 📈 +17
Failed Tests
Skipped Tests

All tests are passing successfully.

❌ Patch coverage is 72.92%. Project has 13142 uncovered lines.
❌ Project coverage is 75.89%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
src/lib/init/wizard-runner.ts 5.26% ⚠️ 18 Missing
src/commands/log/view.ts 78.13% ⚠️ 7 Missing
src/lib/errors.ts 97.22% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    75.97%    75.89%    -0.08%
==========================================
  Files          294       294         —
  Lines        54402     54503      +101
  Branches         0         0         —
==========================================
+ Hits         41329     41361       +32
- Misses       13073     13142       +69
- Partials         0         0         —

Generated by Codecov Action

BYK added 4 commits April 29, 2026 05:07
sentry api wraps API errors in OutputError (renders response to stdout),
so the exit code is OUTPUT_ERROR (60), not API (30).

Trace view gets 200 with empty array for non-existent traces, so it
throws ValidationError (21), not ApiError (30).
…utionError

- CliError base constructor now uses EXIT.GENERAL instead of hardcoded 1
- trace/view: 'no trace found' throws ResolutionError (exit 23) instead
  of ValidationError (exit 21) — the user provided a valid ID that
  couldn't be resolved, not malformed input
- log/view: same fix for throwNotFoundError — 'log not found' is a
  resolution failure, not a validation failure
- exit-codes.md: document sentry api OutputError behavior, fix Python
  example to use range checks
- agent-guidance.md: add 50-69 ranges to exit code table
Comment thread src/commands/log/view.ts Outdated
Comment thread src/commands/trace/view.ts Outdated
BYK added 3 commits April 29, 2026 05:49
…slug

- log/view: restructure multi-log ResolutionError to keep headline
  single-line ('2 log(s) not found in org/project') and move IDs to
  suggestions list, avoiding awkward period placement
- trace/view: include project slug in ResolutionError hint so the
  suggested command doesn't immediately fail with ContextError
Add wizard sub-codes in the 60s range (62=deps, 63=codemod, 64=verify)
so scripts can distinguish wizard failure categories. The remote
workflow's internal codes (20, 30, 40/41, 50) are mapped to EXIT.*
constants in mapWorkflowExitCode() before reaching process exit.

Platform-not-detected (workflow code 20) maps to EXIT.CONFIG (20) since
it's fundamentally a project configuration issue.
Comment thread src/commands/trace/view.ts Outdated
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 78c6803. Configure here.

Comment thread src/lib/init/wizard-runner.ts
- trace/view: guard project with fallback placeholder in hint to avoid
  interpolating 'undefined' as a literal string
- wizard-runner: use EXIT_PLATFORM_NOT_DETECTED, EXIT_DEPENDENCY_INSTALL_FAILED,
  EXIT_VERIFICATION_FAILED constants instead of magic numbers
@BYK BYK merged commit 08192f8 into main Apr 29, 2026
26 checks passed
@BYK BYK deleted the feat/standardize-exit-codes branch April 29, 2026 07:36
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.

Standardize exit codes across all CLI commands

1 participant