{"record":{"id":"33a16024fa07dbb4","repo":"stablyai/orca","slug":"name-must-be-a-positive-integer-received-val-33a160","errorCode":null,"errorMessage":"${name} must be a positive integer, received ${value}","messagePattern":"(.+?) must be a positive integer, received (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/scripts/branch-compare-head-benchmark.mjs","lineNumber":32,"sourceCode":"// Both arms are compared for identical resolved values before timing.\n//\n// Run with:  node config/scripts/branch-compare-head-benchmark.mjs\nimport { execFile } from 'node:child_process'\nimport { performance } from 'node:perf_hooks'\nimport { fileURLToPath } from 'node:url'\nimport { readBranchCompareHead } from '../../src/shared/git-branch-compare-head.ts'\n\nconst REPO_ROOT = fileURLToPath(new URL('../..', import.meta.url))\nconst ITERATIONS = Number(process.env.ORCA_BRANCH_COMPARE_BENCH_ITERATIONS ?? '8')\nconst WARMUP = Number(process.env.ORCA_BRANCH_COMPARE_BENCH_WARMUP ?? '2')\nconst ROUNDS = 6\n\nfor (const [name, value] of [\n  ['ORCA_BRANCH_COMPARE_BENCH_ITERATIONS', ITERATIONS],\n  ['ORCA_BRANCH_COMPARE_BENCH_WARMUP', WARMUP]\n]) {\n  if (!Number.isSafeInteger(value) || value <= 0) {\n    throw new Error(`${name} must be a positive integer, received ${value}`)\n  }\n}\n\nfunction git(args) {\n  return new Promise((resolve, reject) => {\n    execFile('git', args, { cwd: REPO_ROOT, maxBuffer: 64 * 1024 * 1024 }, (error, stdout) =>\n      error ? reject(error) : resolve(stdout.trim())\n    )\n  })\n}\n\nasync function probeOid(qualifiedRef) {\n  try {\n    const out = await git(['rev-parse', '--verify', '--quiet', `${qualifiedRef}^{commit}`])\n    return out.length > 0 ? out : null\n  } catch {\n    return null\n  }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/branch-compare-head-benchmark.mjs#L14-L50","documentation":"Thrown by the branch-compare-head benchmark when ORCA_BRANCH_COMPARE_BENCH_ITERATIONS or _WARMUP is not a safe positive integer. Uses Number(env) and Number.isSafeInteger, so NaN (non-numeric/empty), floats, zero/negative, and values beyond MAX_SAFE_INTEGER all fail. Defaults are 8 iterations and 2 warmup because each iteration spawns many git processes.","triggerScenarios":"Setting ORCA_BRANCH_COMPARE_BENCH_ITERATIONS to a non-numeric string, a float, zero, or a very large number; unsetting and the env layer returned an empty string instead of undefined.","commonSituations":"Operator bumps iterations to '100' for a longer run but typos to '1o0'; CI matrix injects an empty string for an unset var; attempting to scale iterations high enough to exceed MAX_SAFE_INTEGER.","solutions":["Set each env var to a positive integer, e.g. ORCA_BRANCH_COMPARE_BENCH_ITERATIONS=8 ORCA_BRANCH_COMPARE_BENCH_WARMUP=2 (defaults).","Unset both to use the defaults — note each iteration spawns ~8 git processes so larger values are slow.","Validate in CI with ^[1-9][0-9]*$ before running.","Keep iterations modest (<=50) — this benchmark times real git spawns, so wall-clock grows linearly."],"exampleFix":"// before\n// ORCA_BRANCH_COMPARE_BENCH_ITERATIONS='' node config/scripts/branch-compare-head-benchmark.mjs\n// -> 'ORCA_BRANCH_COMPARE_BENCH_ITERATIONS must be a positive integer, received NaN'\n\n// after\n// unset ORCA_BRANCH_COMPARE_BENCH_ITERATIONS\n// node config/scripts/branch-compare-head-benchmark.mjs","handlingStrategy":"validation","validationCode":"function readPositiveSafeIntEnv(name, fallback) {\n  const raw = process.env[name]\n  if (raw == null || raw === '') return fallback\n  const n = Number(raw)\n  if (!Number.isSafeInteger(n) || n <= 0) {\n    throw new Error(`${name} must be a positive safe integer, got '${raw}'`)\n  }\n  return n\n}\n// const ITERATIONS = readPositiveSafeIntEnv('ORCA_BRANCH_COMPARE_BENCH_ITERATIONS', 8)","typeGuard":"function isPositiveSafeInteger(value) {\n  return Number.isSafeInteger(value) && value > 0\n}","tryCatchPattern":null,"preventionTips":["Prefer unsetting the env var to use the defaults (8/2) — each iteration spawns ~8 git processes.","Keep iteration counts modest (<=50); this benchmark times real git spawns and wall-clock is linear.","Validate env in CI with ^[1-9][0-9]*$."],"tags":["benchmark","env-var","validation","integer","git"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}