Repository navigation
CLI: one error: line for a flag with no path, an invalid schema, or a $ref that does not resolve - #882
Draft
claude[bot] wants to merge 3 commits into
Draft
CLI: one error: line for a flag with no path, an invalid schema, or a $ref that does not resolve#882claude[bot] wants to merge 3 commits into
error: line for a flag with no path, an invalid schema, or a $ref that does not resolve#882claude[bot] wants to merge 3 commits into
Conversation
… a `$ref` that does not resolve Three user mistakes still printed an internal stack trace after the CLI's own usage errors became one line: - `json2ts schema.json -o` / `json2ts -i` (and `--output=`): the flag's value was boolean `true` (or ''), which reached path.resolve() as a TypeError with a stack. Now: `error: --output (-o) needs a path after it, e.g. -o schema.d.ts`. - An invalid schema: compile() prints one line per rule the schema breaks, then the CLI printed the ValidationError it throws (empty message, three frames). Now only the rule lines are printed. - A `$ref` json-schema-ref-parser cannot resolve (a missing or unparsable file, a pointer to nothing): its error was printed with the stack and its fields. Now the message alone, one line per error, with `(in <file>)` appended when the message does not already name the file the `$ref` was found in. Invalid JSON on stdin also said `in file "null"`; it now says `from standard input`. Exit codes are unchanged (1) and generated output is untouched.
claude Bot
pushed a commit
that referenced
this pull request
Sep 7, 2026
…chema, or an unresolved $ref) into the UserError branch Both change main()'s catch block and parseFileAsJSONSchema's stdin wording. The catch now prints a UserError's message alone, one line per json-schema-ref-parser error, nothing more for a ValidationError, and the error with its stack otherwise; the --input/--output guard reads the flag's values as a list, which covers #882's empty-value case and this branch's repeated-flag case.
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.
Three mistakes a person can make at the command line still printed an internal stack trace, after #876 made the CLI's own usage errors one
error:line. Each is now one plain line saying what to fix. Exit codes are unchanged (1) and generated output is untouched.Before / after
A path flag with nothing after it (
-i,-o,--output=):An invalid schema (
compile()already prints one line per rule it breaks; the CLI then printed the emptyValidationErrorit throws):A
$refthat does not resolve (a missing or unparsable file, a pointer to nothing; json-schema-ref-parser's error was printed whole, with its stack and fields):When the resolver's message does not name the file the
$refsits in (a pointer into another file that has no such definition), the line says which file:error: Missing $ref pointer "#/definitions/nope". Token "nope" does not exist. (in /…/other.json). A pointer into the schema itself gets no suffix (the resolver's source for it is just the working directory). With--$refOptions.continueOnError, every collected error gets its own line.Also: invalid JSON on standard input said
Error parsing JSON in file "null"; it now saysError parsing JSON from standard input.What is deliberately unchanged
json2ts -i missing.json) and malformed JSON or YAML in a file still print the stack, as CLI: print a usage error as oneerror: …line, and parse--inferStringEnumKeysFromValues=falseas false #876 chose: they name the path, and the stack says where in the program it failed.in file "NoName"label for a schema piped in is the name the generated root type is derived from, so it is not touched here.How
src/cli.ts:--input/--outputgiven as booleantrue(nothing after the flag) or''is aUsageError, checked before the value reachesisDynamicPatternorpath.resolve. The catch block printse.messagefor aUsageError, one message per error for json-schema-ref-parser'sJSONParserError/JSONParserErrorGroup, nothing more for aValidationError, and the error itself (with stack) for anything else.src/utils.ts: the stdin parse message.Tests
Eight new
cliFailTests intest/cli.test.ts(-oat the end of the line,--output=,-ialone, invalid schema on stdin, invalid JSON on stdin, a$refto a missing file, a$refto a missing pointer in another file, a$refto a missing pointer in the schema itself); each asserts exit 1, the message, and where it applies that stderr is one line with noatframe. All fail on master.CI=true bun run test: 688 pass, lint, format and typecheck clean.