Skip to content

fix(cli): surface clear error for duplicate -o instead of internal error#2972

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-2457
Jul 20, 2026
Merged

fix(cli): surface clear error for duplicate -o instead of internal error#2972
schani merged 1 commit into
masterfrom
agent/fix-issue-2457

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

Passing a singular CLI option twice — e.g. -o list.go -o list.ts — produced an opaque, unhelpful error:

Error: Internal error: Partial option parsing should not have failed.

Repro

node dist/index.js -o list.go -o list.ts --package transport --src-lang schema ./list.schema.json

Root cause

command-line-args throws ALREADY_SET ("Singular option already set [out=...]") when a singular option like -o/--out is passed more than once — even when parsing with partial: true. quicktype's parseOptions() in src/index.ts wrapped the parse call in a try/catch that asserted partial parsing could never throw:

} catch (e) {
    assert(!partial, "Partial option parsing should not have failed");
    return messageError("DriverCLIOptionParsingFailed", { message: exceptionToString(e) });
}

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 same messageError path as non-partial ones, surfacing the library's actual message.

Test coverage

Added test/unit/cli-options.test.ts, which calls parseCLIOptions(["-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 build passes.
  • npm run test:unit — all 164 tests pass (26 files), including the new test.
  • Manually re-ran the repro against the built CLI:
    $ node dist/index.js -o list.go -o list.ts --package transport --src-lang schema ./list.schema.json
    Error: Option parsing failed: ALREADY_SET: Singular option already set [out=list.go].
    
    Exit code 1, clear message, no more "Internal error".

Fixes #2457

🤖 Generated with Claude Code

…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>
@schani
schani merged commit 7e694d9 into master Jul 20, 2026
28 checks passed
@schani
schani deleted the agent/fix-issue-2457 branch July 20, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Partial option parsing should not have failed"

1 participant