{"record":{"id":"03416b01699144d0","repo":"stablyai/orca","slug":"name-must-be-a-positive-integer-received-val-03416b","errorCode":null,"errorMessage":"${name} must be a positive integer, received ${value}","messagePattern":"(.+?) must be a positive integer, received (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/markdown-toc-parse-benchmark.mjs","lineNumber":34,"sourceCode":"import remarkGfm from 'remark-gfm'\nimport remarkParse from 'remark-parse'\nimport { unified } from 'unified'\n\nconst DOC_HEADINGS = Number.parseInt(process.env.ORCA_TOC_BENCH_HEADINGS ?? '400', 10)\nconst PARAGRAPHS_PER_HEADING = Number.parseInt(process.env.ORCA_TOC_BENCH_PARAS ?? '6', 10)\n// Number of debounced content changes in a sustained typing burst. The editor\n// debounces serialize at 300ms, so ~200 changes ≈ a minute of steady typing.\nconst CONTENT_CHANGES = Number.parseInt(process.env.ORCA_TOC_BENCH_CHANGES ?? '200', 10)\nconst WARMUP = Number.parseInt(process.env.ORCA_TOC_BENCH_WARMUP ?? '5', 10)\n\nfor (const [name, value] of [\n  ['ORCA_TOC_BENCH_HEADINGS', DOC_HEADINGS],\n  ['ORCA_TOC_BENCH_PARAS', PARAGRAPHS_PER_HEADING],\n  ['ORCA_TOC_BENCH_CHANGES', CONTENT_CHANGES],\n  ['ORCA_TOC_BENCH_WARMUP', WARMUP]\n]) {\n  if (!Number.isInteger(value) || value <= 0) {\n    throw new Error(`${name} must be a positive integer, received ${value}`)\n  }\n}\n\n// Mirror of buildMarkdownTableOfContents()'s parse + heading walk\n// (src/renderer/src/components/editor/markdown-table-of-contents.ts). Kept inline\n// so the benchmark exercises the real remark pipeline without bundling the TS.\nfunction buildMarkdownTableOfContentsLike(markdown) {\n  const tree = unified()\n    .use(remarkParse)\n    .use(remarkGfm)\n    .use(remarkFrontmatter, ['yaml', 'toml'])\n    .parse(markdown)\n  const headings = []\n  const visit = (node) => {\n    if (node.type === 'heading' && typeof node.depth === 'number') {\n      let title = ''\n      const collect = (n) => {\n        if (typeof n.value === 'string') {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/markdown-toc-parse-benchmark.mjs#L16-L52","documentation":"Startup guard in the markdown TOC parse benchmark. It Number.parseInt's four env vars (ORCA_TOC_BENCH_HEADINGS, _PARAS, _CHANGES, _WARMUP) with a decimal radix and rejects anything that is not an integer > 0. NaN (non-numeric or empty string), zero, and negatives all fail. The error names which var is bad and what was received.","triggerScenarios":"Setting any of the four ORCA_TOC_BENCH_* env vars to a non-numeric string, empty string, '0', a negative number, or a float like '5.5' (parseInt truncates, but '5.5' still parses to 5 so only NaN/<=0 fail).","commonSituations":"Typo in the env var name in CI matrix config; exporting with shell quoting that leaves an empty value (ORCA_TOC_BENCH_HEADINGS=); inheriting a value from a different benchmark's var set; or setting a float expecting it to be honored.","solutions":["Unset the offending var to fall back to the documented default (400/6/200/5)","Set it to a positive integer literal: ORCA_TOC_BENCH_HEADINGS=400 node markdown-toc-parse-benchmark.mjs","Check for trailing whitespace or quotes in the export: printf '%s' \"$ORCA_TOC_BENCH_HEADINGS\" | od -c","If driving from a script, validate with a positive-integer regex before exporting"],"exampleFix":"# before\nexport ORCA_TOC_BENCH_HEADINGS=\nnode config/scripts/markdown-toc-parse-benchmark.mjs\n\n# after\nunset ORCA_TOC_BENCH_HEADINGS\nnode config/scripts/markdown-toc-parse-benchmark.mjs","handlingStrategy":"validation","validationCode":"function positiveIntEnv(name, fallback) {\n  const raw = process.env[name]\n  if (raw === undefined) return fallback\n  if (!/^[1-9][0-9]*$/.test(raw)) {\n    throw new Error(`${name} must be a positive integer, received ${raw}`)\n  }\n  return Number.parseInt(raw, 10)\n}","typeGuard":"function isPositiveInt(v) {\n  return Number.isInteger(v) && v > 0\n}","tryCatchPattern":null,"preventionTips":["Validate env vars in the wrapping CI script with ^[1-9][0-9]*$ before exporting","Unset vars to use documented defaults rather than passing empty strings","Inspect exported values with printf '%s' \"$VAR\" | od -c to catch whitespace"],"tags":["env-validation","configuration","benchmark","startup-guard"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}