{"record":{"id":"143cd9e8b94374ac","repo":"chenglou/pretext","slug":"invalid-value-for-name-raw-143cd9","errorCode":null,"errorMessage":"Invalid value for --${name}: ${raw}","messagePattern":"Invalid value for --(.+?): (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/probe-check.ts","lineNumber":75,"sourceCode":"      unitWidth: number\n      lineFitWidth: number\n      marker: 'ours' | 'browser' | 'ours+browser' | null\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)) throw new Error(`Invalid value for --${name}: ${raw}`)\n  return parsed\n}\n\nfunction parseBrowser(value: string | null): BrowserKind {\n  const browser = (value ?? process.env['PROBE_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 requireFlag(name: string): string {\n  const value = parseStringFlag(name)\n  if (value === null || value.length === 0) throw new Error(`Missing --${name}=...`)\n  return value\n}\n\nfunction printReport(report: ProbeReport): void {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/probe-check.ts#L57-L93","documentation":"parseNumberFlag (shared CLI helper in scripts/probe-check.ts) parses a --<name>=<raw> argument as a base-10 integer and throws when Number.parseInt(raw, 10) returns NaN. It guards --port, --width, and --lineHeight for the single-case diagnostic probe. Because it uses parseInt, '12.5' silently becomes 12 (no throw) while '', 'abc', '--', and '3px' all throw.","triggerScenarios":"bun run scripts/probe-check.ts --text=hi --width=abc; --port= (empty); --lineHeight=2em; any non-integer token for those three flags. parseNumberFlag is called at module top-level (lines 146,148,151), so the throw happens before any browser work starts.","commonSituations":"Typos in flag values; copy-pasting CSS units (18px) into a numeric flag; shell quoting that strips the value leaving --width=.","solutions":["Pass a plain base-10 integer: --width=600, --port=0, --lineHeight=32.","Remember numeric flags are unitless; keep CSS units on --font (e.g. --font=18px serif) only.","Read the error message: it echoes the offending flag name and the raw value you passed."],"exampleFix":"# before\nbun run scripts/probe-check.ts --text=hi --width=600px --lineHeight=32\n\n# after\nbun run scripts/probe-check.ts --text=hi --width=600 --lineHeight=32","handlingStrategy":"validation","validationCode":"const isIntFlag = (raw: string | null): boolean =>\n  raw === null || /^-?\\d+$/.test(raw.trim())\nconst raw = parseStringFlag('width')\nif (!isIntFlag(raw)) {\n  console.error(`--width expects an integer, got ${JSON.stringify(raw)}`)\n  process.exit(2)\n}","typeGuard":"const isIntFlag = (s: string | null): s is string =>\n  s !== null && Number.isFinite(Number.parseInt(s, 10))","tryCatchPattern":null,"preventionTips":["Numeric flags for probe-check (--port, --width, --lineHeight) are unitless integers; keep CSS units on --font only.","parseInt('12.5') silently truncates to 12 — if you meant a fraction, you will not get an error, so double-check float-ish inputs.","Read the error message: it names the bad flag and echoes the raw value."],"tags":["cli","argument-parsing","typescript"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}