feat(cli)!: document exit codes, usage errors use exit code 2#8329
Conversation
- New EXIT_CODES dictionary (0 ok, 1 error, 2 usage, 4 needs-input), surfaced in the root --help epilogue - Commander usage errors (unknown command/option, bad or missing arguments) now exit 2 instead of 1 - Unknown-command did-you-mean output moves from stdout to stderr so stdout stays clean for machine consumers
📊 Benchmark resultsComparing with 8943e38
|
📝 WalkthroughWalkthroughThis PR introduces a structured EXIT_CODES contract (SUCCESS, GENERAL_ERROR, USAGE_ERROR, NON_INTERACTIVE_PROMPT) and a USAGE_ERROR_CODES set aggregating Commander error codes for usage-related failures. Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsRepository analysis: Couldn't refresh Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/commands/main.ts (1)
208-210: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNew "what the code does" comment violates coding guideline.
These three lines explain what the following block does. As per coding guidelines,
**/*.{ts,tsx,js,jsx}should "Never write comments on what the code does; make the code clean and self-explanatory instead."♻️ Proposed removal
- // In non-interactive environments (CI/CD, scripts), show the suggestion - // without prompting, and display full help for available commands. - // Diagnostics belong on stderr so stdout stays clean for machine consumers. if (!isInteractive()) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/main.ts` around lines 208 - 210, Remove the explanatory comment in the non-interactive handling block in main.ts, since it restates what the code already does and violates the no-comment guideline. Keep the logic in the surrounding non-interactive flow self-explanatory, and if needed rely on the existing code structure around the command suggestion/help output and stderr diagnostics instead of adding a narrative comment.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/commands/main.ts`:
- Around line 208-210: Remove the explanatory comment in the non-interactive
handling block in main.ts, since it restates what the code already does and
violates the no-comment guideline. Keep the logic in the surrounding
non-interactive flow self-explanatory, and if needed rely on the existing code
structure around the command suggestion/help output and stderr diagnostics
instead of adding a narrative comment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d9d1e639-b321-4a53-9ad4-7308af62ff9e
⛔ Files ignored due to path filters (2)
tests/integration/commands/didyoumean/__snapshots__/didyoumean.test.ts.snapis excluded by!**/*.snaptests/integration/commands/help/__snapshots__/help.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (6)
src/commands/main.tssrc/utils/command-error-handler.tssrc/utils/exit-codes.tssrc/utils/run-program.tstests/integration/commands/didyoumean/didyoumean.test.tstests/unit/utils/exit-codes.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
netlify/blueprints(manual)
🤖 I have created a release *beep* *boop* --- ## [27.0.0](v26.2.0...v27.0.0) (2026-07-24) ### ⚠ BREAKING CHANGES * **cli:** document exit codes, usage errors use exit code 2 ([#8329](#8329)) * drop support for Node.js 20, require 22.13.0+ ([#8356](#8356)) ### Features * **cli:** document exit codes, usage errors use exit code 2 ([#8329](#8329)) ([9098467](9098467)) * drop support for Node.js 20, require 22.13.0+ ([#8356](#8356)) ([8943e38](8943e38)) ### Bug Fixes * **cli:** piped --help no longer glues flag names to descriptions ([#8330](#8330)) ([4b87cc7](4b87cc7)) * **init:** fix handling of gitlab repos ([#7945](#7945)) ([f214e69](f214e69)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Potentially breaking change: Usage errors (e.g. invalid command) now exit with exit code 2 (previously 1).
Split from #8300 (1 of 9).
What
0ok ·1error ·2usage error ·4input needed (src/utils/exit-codes.ts), shown in the root--helpfooter2instead of1Why it helps agents
Agents and scripts branch on exit codes. Today every failure exits
1, so a typo'd flag is indistinguishable from a failed deploy — retry logic can't tell "fix the command" from "the operation failed." Keeping suggestions on stderr means stdout stays parseable.New codes only appear on paths that already failed; nothing that exited 0 changes.
Testing
Stacked PRs that build on this: space-form subcommand guard,
--non-interactive(exit 4).