{"record":{"id":"6139a2769008d16b","repo":"chenglou/pretext","slug":"invalid-value-for-name-raw","errorCode":null,"errorMessage":"Invalid value for --${name}: ${raw}","messagePattern":"Invalid value for --(.+?): (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/benchmark-check.ts","lineNumber":84,"sourceCode":"  'analysisSegments',\n  'segments',\n  'breakableSegments',\n  'width',\n  'lineCount',\n] as const\n\nfunction parseStringFlag(name: string): string | null {\n  const prefix = `--${name}=`\n  const arg = process.argv.find(value => value.startsWith(prefix))\n  return arg === undefined ? null : arg.slice(prefix.length)\n}\n\nfunction parseNumberFlag(name: string, fallback: number): number {\n  const raw = parseStringFlag(name)\n  if (raw === null) return fallback\n  const parsed = Number.parseInt(raw, 10)\n  if (!Number.isFinite(parsed)) {\n    throw new Error(`Invalid value for --${name}: ${raw}`)\n  }\n  return parsed\n}\n\nfunction parseBrowser(value: string | null): BrowserKind {\n  const browser = (value ?? process.env['BENCHMARK_CHECK_BROWSER'] ?? 'chrome').toLowerCase()\n  if (browser !== 'chrome' && browser !== 'safari') {\n    throw new Error(`Unsupported browser ${browser}; expected chrome or safari`)\n  }\n  return browser\n}\n\nfunction median(values: number[]): number {\n  const sorted = [...values].sort((a, b) => a - b)\n  const mid = Math.floor(sorted.length / 2)\n  return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/benchmark-check.ts#L66-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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]+$/."],"exampleFix":"# before\nbun run scripts/benchmark-check.ts --runs=$RUNS   # RUNS unset -> '--runs='\n\n# after\nRUNS=\"${RUNS:-3}\"\nbun run scripts/benchmark-check.ts --runs=\"$RUNS\"","handlingStrategy":"validation","validationCode":"// Validate numeric flags before the script parses them.\nfunction parseNumberFlag(name: string, fallback: number): number {\n  const raw = parseStringFlag(name)\n  if (raw === null) return fallback\n  if (!/^-?\\d+$/.test(raw)) throw new Error(`Invalid value for --${name}: ${raw}`)\n  return Number.parseInt(raw, 10)\n}","typeGuard":"function isIntegerFlag(value: string): boolean {\n  return /^-?\\d+$/.test(value)\n}","tryCatchPattern":"// Wrap the whole CLI entry so flag errors exit cleanly with a message.\ntry {\n  const runs = parseNumberFlag('runs', 3)\n  // ...\n} catch (error) {\n  console.error(error instanceof Error ? error.message : String(error))\n  process.exit(2)\n}","preventionTips":["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."],"tags":["benchmark-check","cli-flag","validation","config"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}