{"record":{"id":"8e8eee1ae7733651","repo":"chenglou/pretext","slug":"invalid-value-for-runs-runs-expected-an-int","errorCode":null,"errorMessage":"Invalid value for --runs: ${runs}; expected an integer >= 1","messagePattern":"Invalid value for --runs: (.+?); expected an integer >= 1","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/benchmark-check.ts","lineNumber":258,"sourceCode":"  }\n\n  if ((report.corpusResults ?? []).length > 0) {\n    console.log('Long-form corpus stress:')\n    for (const corpus of report.corpusResults!) {\n      console.log(\n        `  ${corpus.label}: analyze ${corpus.analysisMs.toFixed(2)}ms | measure ${corpus.measureMs.toFixed(2)}ms | prepare ${corpus.prepareMs.toFixed(2)}ms | layout ${corpus.layoutMs < 0.01 ? '<0.01' : corpus.layoutMs.toFixed(2)}ms | ${corpus.analysisSegments.toLocaleString()}→${corpus.segments.toLocaleString()} segs | ${corpus.lineCount} lines @ ${corpus.width}px`,\n      )\n    }\n  }\n}\n\nconst browser = parseBrowser(parseStringFlag('browser'))\nconst requestedPort = parseNumberFlag('port', Number.parseInt(process.env['BENCHMARK_CHECK_PORT'] ?? '0', 10))\nconst runs = parseNumberFlag('runs', Number.parseInt(process.env['BENCHMARK_CHECK_RUNS'] ?? '3', 10))\nconst output = parseStringFlag('output')\n\nif (!Number.isInteger(runs) || runs < 1) {\n  throw new Error(`Invalid value for --runs: ${runs}; expected an integer >= 1`)\n}\n\nlet serverProcess: ChildProcess | null = null\nconst lock = await acquireBrowserAutomationLock(browser)\nconst session = createBrowserSession(browser, { foreground: true })\n\ntry {\n  const port = await getAvailablePort(requestedPort === 0 ? null : requestedPort)\n  const pageServer = await ensurePageServer(port, '/benchmark', process.cwd())\n  serverProcess = pageServer.process\n  const baseUrl = `${pageServer.baseUrl}/benchmark`\n\n  const reports: BenchmarkReport[] = []\n  for (let runIndex = 0; runIndex < runs; runIndex++) {\n    const requestId = `${Date.now()}-${runIndex}-${Math.random().toString(36).slice(2)}`\n    const url =\n      `${baseUrl}?report=1` +\n      `&requestId=${encodeURIComponent(requestId)}`","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/benchmark-check.ts#L240-L276","documentation":"Thrown at benchmark-check.ts:257-259 after parsing the --runs flag (or BENCHMARK_CHECK_RUNS env, default 3). Even though parseNumberFlag already rejected non-finite values (error 6), this additional check requires runs to be a positive integer (Number.isInteger AND >= 1). It catches cases where parseInt produced a finite-but-invalid number like 0 or a negative. Because the env fallback path can produce NaN from an empty BENCHMARK_CHECK_RUNS, this guard also catches that leaked NaN.","triggerScenarios":"Passing --runs=0, --runs=-2, or exporting BENCHMARK_CHECK_RUNS= (empty string, which parseInts to NaN and bypasses parseNumberFlag's finite check via the fallback path). Note: --runs=2.5 parses to 2 via parseInt and would PASS both checks (a known leniency). Only truly non-positive or non-integer (NaN) values are rejected here.","commonSituations":"Wanting 'no repeats' and guessing --runs=0; a CI template setting BENCHMARK_CHECK_RUNS='' ; a negative value from an arithmetic expression; an off-by-one in a wrapper script computing runs from a count.","solutions":["Use --runs=1 or higher (e.g. --runs=5 for a stable median).","If BENCHMARK_CHECK_RUNS is templated, default it: BENCHMARK_CHECK_RUNS=\"${BENCHMARK_CHECK_RUNS:-3}\".","Audit the env for an empty BENCHMARK_CHECK_RUNS assignment.","Do not pass fractional or zero values; the harness needs at least one run."],"exampleFix":"# before\nexport BENCHMARK_CHECK_RUNS=\n\n# after\nunset BENCHMARK_CHECK_RUNS   # uses default 3\n# or\nexport BENCHMARK_CHECK_RUNS=5","handlingStrategy":"validation","validationCode":"// Validate runs explicitly before the script's own check.\nconst runs = parseNumberFlag('runs', Number.parseInt(process.env.BENCHMARK_CHECK_RUNS ?? '3', 10))\nif (!Number.isInteger(runs) || runs < 1) {\n  throw new Error(`Invalid value for --runs: ${runs}; expected an integer >= 1`)\n}","typeGuard":"function isPositiveInteger(value: number): boolean {\n  return Number.isInteger(value) && value >= 1\n}","tryCatchPattern":null,"preventionTips":["Default BENCHMARK_CHECK_RUNS with parameter expansion: BENCHMARK_CHECK_RUNS=\"${BENCHMARK_CHECK_RUNS:-3}\".","Never pass --runs=0; use --runs=1 for a single-shot benchmark.","Audit env files for empty BENCHMARK_CHECK_RUNS assignments (parseInt('') is NaN)."],"tags":["benchmark-check","config","validation","cli-flag"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}