chenglou/pretext · error · Error
Invalid value for --${name}: ${raw}
Error message
Invalid value for --${name}: ${raw} What it means
Thrown by parseNumberFlag() in benchmark-check.ts when a --<name>=<value> argument is present on the command line but Number.parseInt(value, 10) is not finite. It is the generic guard for every numeric CLI flag used by the benchmark script (currently --port and --runs). A flag that is absent returns the fallback and does not throw; only a present-but-non-numeric value does.
Source
Thrown at scripts/benchmark-check.ts:84
'analysisSegments',
'segments',
'breakableSegments',
'width',
'lineCount',
] as const
function parseStringFlag(name: string): string | null {
const prefix = `--${name}=`
const arg = process.argv.find(value => value.startsWith(prefix))
return arg === undefined ? null : arg.slice(prefix.length)
}
function parseNumberFlag(name: string, fallback: number): number {
const raw = parseStringFlag(name)
if (raw === null) return fallback
const parsed = Number.parseInt(raw, 10)
if (!Number.isFinite(parsed)) {
throw new Error(`Invalid value for --${name}: ${raw}`)
}
return parsed
}
function parseBrowser(value: string | null): BrowserKind {
const browser = (value ?? process.env['BENCHMARK_CHECK_BROWSER'] ?? 'chrome').toLowerCase()
if (browser !== 'chrome' && browser !== 'safari') {
throw new Error(`Unsupported browser ${browser}; expected chrome or safari`)
}
return browser
}
function median(values: number[]): number {
const sorted = [...values].sort((a, b) => a - b)
const mid = Math.floor(sorted.length / 2)
return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!
}
View on GitHub (pinned to ac49b09b7d)
Solutions
- Supply a valid integer: --runs=5 or --port=8080.
- If the value is templated, ensure the source variable is set and numeric before interpolation.
- Remove the flag to accept its fallback (--port falls back to BENCHMARK_CHECK_PORT env or 0; --runs falls back to BENCHMARK_CHECK_RUNS or 3).
- Quote and validate the value before passing it: only forward it when it matches /^[0-9]+$/.
Example fix
# before
bun run scripts/benchmark-check.ts --runs=$RUNS # RUNS unset -> '--runs='
# after
RUNS="${RUNS:-3}"
bun run scripts/benchmark-check.ts --runs="$RUNS" Defensive patterns
Strategy: validation
Validate before calling
// Validate numeric flags before the script parses them.
function parseNumberFlag(name: string, fallback: number): number {
const raw = parseStringFlag(name)
if (raw === null) return fallback
if (!/^-?\d+$/.test(raw)) throw new Error(`Invalid value for --${name}: ${raw}`)
return Number.parseInt(raw, 10)
} Type guard
function isIntegerFlag(value: string): boolean {
return /^-?\d+$/.test(value)
} Try / catch
// Wrap the whole CLI entry so flag errors exit cleanly with a message.
try {
const runs = parseNumberFlag('runs', 3)
// ...
} catch (error) {
console.error(error instanceof Error ? error.message : String(error))
process.exit(2)
} Prevention
- Quote interpolated variables: `--runs="${RUNS:-3}"` so an unset var becomes the default, not empty.
- Validate templated values before invoking the script.
- Remember parseInt is lenient with trailing chars ('300px' -> 300); validate with a regex if strictness matters.
When it happens
Trigger: Passing --port=abc, --runs=many, --port= (empty), or any --<numericFlag>=<non-integer-leading> value. Because parseInt stops at the first non-digit, '300px' parses to 300 and does NOT throw; only values with no leading digit run afoul.
Common situations: Typos in the CLI invocation (--runs=thre); copy-pasting a flag value that included a unit or comment; a wrapper script interpolating an unset variable as the value (`--runs=$RUNS` where RUNS is empty).
Related errors
- Invalid value for --runs: ${runs}; expected an integer >= 1
- Unsupported browser ${browser}; expected chrome or safari
- Invalid widths parameter: ${raw}
- Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw}
- Unknown corpus ${options.id}. Available corpora: ${sources.m
AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12).
Data as JSON: /api/errors/6139a2769008d16b.
Report an issue: GitHub.