fix(cli): surface clear error for duplicate -o instead of internal error#2972
Merged
Conversation
…ror (#2457) Passing a singular CLI option twice (e.g. `-o a -o b`) made command-line-args throw ALREADY_SET even during partial parsing, which tripped an assert in parseOptions() and surfaced an opaque "Internal error: Partial option parsing should not have failed" instead of the library's clear message. Drop the assert so partial-parse failures flow through the same messageError("DriverCLIOptionParsingFailed", ...) path as non-partial failures. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.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.
Bug
Passing a singular CLI option twice — e.g.
-o list.go -o list.ts— produced an opaque, unhelpful error:Repro
Root cause
command-line-argsthrowsALREADY_SET("Singular option already set [out=...]") when a singular option like-o/--outis passed more than once — even when parsing withpartial: true. quicktype'sparseOptions()insrc/index.tswrapped the parse call in a try/catch that asserted partial parsing could never throw:Since the assertion fired before the library's actual error message could reach the user, the CLI printed a generic "Internal error" instead of routing the failure through the existing
messageError("DriverCLIOptionParsingFailed", ...)path used for non-partial parse failures.Fix
Remove the
assert(!partial, ...)so partial-parse failures flow through the samemessageErrorpath as non-partial ones, surfacing the library's actual message.Test coverage
Added
test/unit/cli-options.test.ts, which callsparseCLIOptions(["-o", "list.go", "-o", "list.ts"])and asserts it throws a message containing "Singular option already set" and does not contain "Internal error". This fails on unfixed code (the internal-error assertion trips) and passes after the fix.This is CLI option-parsing/error-message behavior, not generated-code output for any target language, so it isn't expressible as a JSON/JSON Schema fixture test per repo conventions — a focused unit test is the appropriate coverage here.
Verification
npm run buildpasses.npm run test:unit— all 164 tests pass (26 files), including the new test.Fixes #2457
🤖 Generated with Claude Code