From 24db80635ae14200fae10e5c6730d1e19f8d1dfa Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 16:42:36 -0400 Subject: [PATCH] fix(cli): surface clear error for duplicate -o instead of internal error (#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 --- src/index.ts | 1 - test/unit/cli-options.test.ts | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/unit/cli-options.test.ts diff --git a/src/index.ts b/src/index.ts index 6ae510e25b..d22d5e70f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -751,7 +751,6 @@ function parseOptions( { argv, partial }, ); } catch (e) { - assert(!partial, "Partial option parsing should not have failed"); return messageError("DriverCLIOptionParsingFailed", { message: exceptionToString(e), }); diff --git a/test/unit/cli-options.test.ts b/test/unit/cli-options.test.ts new file mode 100644 index 0000000000..44b22288c9 --- /dev/null +++ b/test/unit/cli-options.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, test } from "vitest"; + +import { parseCLIOptions } from "../../src/index.js"; + +describe("CLI option parsing", () => { + test("reports a duplicate output option as a user input error", () => { + expect(() => + parseCLIOptions(["-o", "list.go", "-o", "list.ts"]), + ).toThrow(/^Option parsing failed: .*Singular option already set/); + + expect(() => + parseCLIOptions(["-o", "list.go", "-o", "list.ts"]), + ).not.toThrow("Internal error"); + }); +});