{"record":{"id":"e580eadd9c07e1f2","repo":"stablyai/orca","slug":"name-must-be-a-positive-integer-received-val-e580ea","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/mjpeg-frame-parser-alloc-benchmark.mjs","lineNumber":37,"sourceCode":"// implementation calls trackedCopy() wherever it would allocate a copy, so the\n// reported \"bytes copied\" is exact and independent of GC timing.\nlet copiedBytes = 0\nfunction trackedCopy(buf) {\n  copiedBytes += buf.length\n  return Buffer.from(buf)\n}\n\nconst FPS = Number.parseInt(process.env.ORCA_MJPEG_BENCH_FPS ?? '30', 10)\nconst SECONDS = Number.parseInt(process.env.ORCA_MJPEG_BENCH_SECONDS ?? '30', 10)\nconst FRAME_BYTES = Number.parseInt(process.env.ORCA_MJPEG_BENCH_FRAME_BYTES ?? '184320', 10) // ~180 KiB\n\nfor (const [name, value] of [\n  ['ORCA_MJPEG_BENCH_FPS', FPS],\n  ['ORCA_MJPEG_BENCH_SECONDS', SECONDS],\n  ['ORCA_MJPEG_BENCH_FRAME_BYTES', FRAME_BYTES]\n]) {\n  if (!Number.isInteger(value) || value <= 0) {\n    throw new Error(`${name} must be a positive integer, received ${value}`)\n  }\n}\n\nconst JPEG_START = Buffer.from([0xff, 0xd8])\nconst JPEG_END = Buffer.from([0xff, 0xd9])\n\nfunction makeFrame(seed) {\n  const body = Buffer.alloc(FRAME_BYTES - 4)\n  // Avoid an accidental 0xff 0xd9 inside the body so the frame boundary is clean.\n  body.fill(seed % 251 || 1)\n  return Buffer.concat([JPEG_START, body, JPEG_END])\n}\n\n// --- old implementation: copy chunk + copy every frame -----------------------\nfunction extractOld(pending, chunk, maxPendingBytes = 2 * 1024 * 1024) {\n  let cursor = pending.length > 0 ? Buffer.concat([pending, chunk]) : trackedCopy(chunk)\n  const frames = []\n  while (cursor.length > 0) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/mjpeg-frame-parser-alloc-benchmark.mjs#L19-L55","documentation":"Startup guard in the MJPEG frame parser allocation benchmark. Identical pattern to the TOC benchmark: Number.parseInt's ORCA_MJPEG_BENCH_FPS, _SECONDS, _FRAME_BYTES with default fallbacks and rejects non-integer or <=0 values, naming the bad var and value.","triggerScenarios":"Any of the three ORCA_MJPEG_BENCH_* env vars set to a non-numeric, empty, zero, or negative value.","commonSituations":"CI matrix exporting the var with a typo; inheriting a frame size tuned for a different resolution that was set to 0; quoting artifacts leaving an empty string.","solutions":["Unset the offending var to fall back to 30/30/184320","Set a positive integer: ORCA_MJPEG_BENCH_FRAME_BYTES=184320 node mjpeg-frame-parser-alloc-benchmark.mjs","Inspect the exported value byte-for-byte: printf '%s' \"$ORCA_MJPEG_BENCH_FPS\" | od -c","Validate in the wrapping script with ^[1-9][0-9]*$ before exporting"],"exampleFix":"# before\nORCA_MJPEG_BENCH_FPS=0 node config/scripts/mjpeg-frame-parser-alloc-benchmark.mjs\n\n# after\nnode config/scripts/mjpeg-frame-parser-alloc-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 in CI before exporting with a positive-integer regex","Unset vars to fall back to 30/30/184320 rather than passing empty values","Check byte-for-byte for whitespace when an unexpected NaN appears"],"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"}