Repository navigation
fix: print CLI errors once, without a stack trace, and honor exitCode - #18
Merged
Merged
Conversation
citty's runMain swallows every error itself: for a non-citty error it prints the error with a stack trace, prints the message again, and always exits 1. So every CliError printed twice with a stack, its exitCode was ignored, and the .catch after runMain never ran. runCli hands --help/--version to runMain and runs everything else through runCommand: CliError -> one "Error: ..." line on stderr + its exitCode; citty usage errors (missing arg, unknown command) are replayed through runMain for its usage rendering (they occur before any command body runs, so no side effects are replayed); unexpected errors -> one line, exit 1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Problem
Every
CliErrorprinted twice with a stack trace, and the exit code was always 1:Cause: citty's
runMainhandles errors itself. For any non-citty error it logs the error with its stack, logs the message again, and callsprocess.exit(1). So the.catchafterrunMaininindex.tsnever ran, andCliError.exitCodewas ignored.Fix
New
src/lib/run.ts(runCli), used byindex.ts:--help/--version→ stillrunMain(it renders them well).runCommand, with our own error handling:CliError→ oneError: …line on stderr, exit with itsexitCode.runMainfor its usage rendering. These are thrown while parsing, before any command body runs, so nothing with side effects is re-executed (covered by a test).Test plan
tests/lib/run.test.ts: single line / no stack / exitCode / no re-run / success / usage error)pixelvault usagewith no key prints one line and exits 1;--version,--helpunchanged🤖 Generated with Claude Code