Repository navigation
fix: exit non-zero on unknown commands and options - #18
Merged
Merged
Conversation
program.exitOverride() makes Commander throw a CommanderError instead of exiting, but the top-level catch dropped every CommanderError (and every non-Error throw), so `silo bogus-cmd` and `silo --bogus` exited 0 after printing the error. Keep Commander's exit code: 0 for --help/--version, 1 for errors. Add tests that run the real entry point and check the exit codes. Fixes SilosLabs#17
Member
|
Thanks for the fix! |
This was referenced Nov 16, 2026
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.
Fixes #17
What
src/cli.ts: the top-levelcatchnow exits witherr.exitCodefor aCommanderError(Commander has already printed the message, help or version text), and exits 1 for any other throw, including non-Errorvalues. Previously everyCommanderError, and anything that wasn't anError, was swallowed with exit 0.tests/cli.test.ts: runs the real entry point (node --import tsx src/cli.ts …, with a throwawayHOME) and checks the exit codes.cli.tsparses argv on import, so it can't be tested in-process.silo bogus-cmdsilo --bogussilo build --bogussilo --help,silo --version,silo build --helpsilo(no command)One behaviour change to check: bare
siloprints help and now exits 1. That's Commander's own default for "no command given" (it prints the help to stderr), and it's whatgitdoes. If you'd rather keep 0 there, it's a one-line special case forerr.code === "commander.help".Testing
npm run typecheck: passes.npm test: 25 files, 345 tests pass (4 new).npm run build: succeeds.cli.ts(both unknown-command and unknown-option cases exit 0) and pass with the fix.src/cli.ts) is clean.