fix(cli): single structured error and correct exit code on input failure#123
Open
rmyndharis wants to merge 1 commit into
Open
fix(cli): single structured error and correct exit code on input failure#123rmyndharis wants to merge 1 commit into
rmyndharis wants to merge 1 commit into
Conversation
…on input failure
On a missing or unreadable input file, readInput printed a structured
FILE_READ_ERROR JSON to stderr and then re-threw. The throw let the CLI
framework print a second, stack-trace error on top of the JSON and override
the exit code with 1 instead of the intended 2. Exit cleanly with code 2
right after the JSON, matching the function's documented "exits with error
JSON" contract.
Also unify the export command's stderr error envelope with readInput's
`{ error: <CODE>, message }` shape: an unknown --format now reports
`INVALID_FORMAT` (the human text moves to `message`), and emitter failures
forward the emitter's structured code (e.g. INVALID_TOKEN_NAME) instead of
discarding it.
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.
Summary
Two related fixes to CLI error reporting.
1. Missing/unreadable input printed a duplicate error and the wrong exit code
readInput(used bylint,diff,export) printed a cleanFILE_READ_ERRORJSON to stderr, then re-threw the underlying error. The throw propagated to the CLI framework, which printed a second error — including areadFileSyncstack trace — on top of the JSON, and exited with code 1 even though the code setprocess.exitCode = 2.Reproduction (before):
design.md lint missing.md→ two stderr blocks (JSON +ERROR ENOENT … at readFileSync …), exit 1.Fix:
process.exit(2)immediately after writing the JSON. This matches the function's own JSDoc ("exits with error JSON"), removes the duplicate stack-trace output, and uses a dedicated I/O exit code (2) distinct from lint-findings (1).2. Inconsistent stderr error envelope
readInputemits{ error: "<CODE>", message, path }, butexportemitted{ error: "<free-text message>" }and discarded the structuredcodethat emitters already return (e.g.INVALID_TOKEN_NAME).Fix:
exportnow emits{ error: "<CODE>", message }—INVALID_FORMATfor an unknown--format, and the emitter's own code forwarded on emitter failure.Behavior change
Exit code on a missing/unreadable input file goes from 1 → 2 (the value the code already intended).
lint/diff/exportare affected; the0/1lint-findings contract is unchanged.Testing
commands/cli-errors.test.ts(spawns the CLI): missing file → exit 2 with exactly one JSON line (FILE_READ_ERROR, no stack trace); unknown export format → exit 1 withINVALID_FORMAT.bun test: 284 pass, 1 skip, 0 fail.bun run lint: clean.{ "error": "INVALID_TOKEN_NAME", "message": … }.