{"record":{"id":"78b704d916f3e793","repo":"chenglou/pretext","slug":"invalid-value-for-name-raw-78b704","errorCode":null,"errorMessage":"Invalid value for --${name}: ${raw}","messagePattern":"Invalid value for --(.+?): (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/corpus-check.ts","lineNumber":129,"sourceCode":"      domWidth: number\n      isSpace: boolean\n    }>\n  } | null\n  message?: string\n}\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['CORPUS_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 parseOptionalNumberFlag(name: string): number | null {\n  const raw = parseStringFlag(name)\n  if (raw === null) return null\n  const parsed = Number.parseInt(raw, 10)\n  if (!Number.isFinite(parsed)) {\n    throw new Error(`Invalid value for --${name}: ${raw}`)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/corpus-check.ts#L111-L147","documentation":"Thrown by parseNumberFlag in corpus-check.ts when a `--name=value` CLI argument is present but Number.parseInt(value, 10) returns NaN. Used for required numeric flags (port, timeout). The thrown name and raw value are interpolated so the offender is identifiable. This is pure input validation at module top-level — the script aborts before doing any browser work.","triggerScenarios":"parseStringFlag('port') finds an arg starting with `--port=`; parseNumberFlag slices the value after `=` and Number.parseInts it. Throw on `--port=abc`, `--port=8080tcp`, `--port=` (empty), `--timeout=30s`. Note parseInt('1.5',10) returns 1 (finite, no throw) — only truly non-numeric prefixes trigger this.","commonSituations":"Copy-pasting a port with a unit suffix; passing an env-var that was empty and got wrapped in `--port=`; quoting mishaps in a CI yaml that turn `--port=$PORT` into `--port=` when PORT is unset; misunderstanding that parseInt is prefix-based so `--port=12abc` parses as 12 silently.","solutions":["Pass a bare base-10 integer: `--port=8765`, `--timeout=180000`.","If sourcing from an env var, default it explicitly: `--port=${CORPUS_CHECK_PORT:-0}` so an unset variable does not yield `--port=`.","Remember parseInt is permissive — `--port=12abc` will NOT throw (it parses as 12); if you need strict validation, augment parseNumberFlag with a full-string regex.","For units (s, ms), convert before passing: `--timeout=$(( 30 * 1000 ))`."],"exampleFix":"// before\nbun run scripts/corpus-check.ts --id=ja-kumo-no-ito --port=8765tcp\n// after\nbun run scripts/corpus-check.ts --id=ja-kumo-no-ito --port=8765","handlingStrategy":"validation","validationCode":"// Validate numeric CLI args before the script's own parse runs\nfunction assertIntFlag(name: string, value: string | undefined): number {\n  if (value === undefined) return NaN\n  if (!/^-?\\d+$/.test(value)) {\n    throw new Error(`--${name} expects a base-10 integer, got ${JSON.stringify(value)}`)\n  }\n  return Number.parseInt(value, 10)\n}","typeGuard":"function isIntegerArg(value: string): boolean {\n  return /^-?\\d+$/.test(value)\n}","tryCatchPattern":null,"preventionTips":["Pass bare integers to numeric flags — never with units or quotes that leave trailing characters.","Default env vars explicitly in the shell (`--port=${PORT:-0}`) to avoid `--port=` when unset.","Remember parseInt is prefix-based: `12abc` parses as 12 silently; use a strict regex if you want full-string rejection."],"tags":["cli","validation","args","corpus-check"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}