{"record":{"id":"9828552520005da5","repo":"denoland/deno","slug":"err-out-of-range-982855","errorCode":"ERR_OUT_OF_RANGE","errorMessage":"The value of \"options.maxBuffer\" is out of range. It must be a positive number. Received ${received}","messagePattern":"The value of \"options\\.maxBuffer\" is out of range\\. It must be a positive number\\. Received (.+?)","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/child_process.ts","lineNumber":585,"sourceCode":"    }\n    // Validate callback if provided\n    if (maybeCallback != null && typeof maybeCallback !== \"function\") {\n      throw new ERR_INVALID_ARG_TYPE(\"callback\", \"function\", maybeCallback);\n    }\n  }\n\n  const execOptions = {\n    __proto__: null,\n    encoding: \"utf8\",\n    timeout: 0,\n    maxBuffer: MAX_BUFFER,\n    killSignal: \"SIGTERM\",\n    shell: false,\n    ...options,\n  };\n  validateTimeout(execOptions.timeout);\n  if (execOptions.maxBuffer < 0) {\n    throw new ERR_OUT_OF_RANGE(\n      \"options.maxBuffer\",\n      \"a positive number\",\n      execOptions.maxBuffer,\n    );\n  }\n  const spawnOptions: SpawnOptions = {\n    argv0: execOptions.argv0,\n    cwd: execOptions.cwd,\n    env: execOptions.env,\n    gid: execOptions.gid,\n    shell: execOptions.shell,\n    signal: execOptions.signal,\n    uid: execOptions.uid,\n    windowsHide: execOptions.windowsHide !== false,\n    windowsVerbatimArguments: !!execOptions.windowsVerbatimArguments,\n  };\n\n  const child = spawn(file, args, spawnOptions);","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/child_process.ts#L567-L603","documentation":"execFile merges user options over defaults (maxBuffer: 1 MiB, timeout: 0) and validates them before spawning. A maxBuffer below zero is rejected with ERR_OUT_OF_RANGE because a buffer cap cannot be negative; the 'positive number' wording mirrors Node's message. Note the check is strictly `maxBuffer < 0` — zero and NaN pass this particular guard (NaN fails comparisons).","triggerScenarios":"execFile('ls', ['-la'], { maxBuffer: -1 }); { maxBuffer: -Infinity }; computed sizes like maxBuffer: quota - used where the subtraction goes negative.","commonSituations":"Sizing buffers from remaining-memory or quota calculations; porting scripts that used negative numbers to mean 'unlimited'; sign typos in config-driven values. timeout is validated first (validateTimeout), so a bad timeout throws its own error before this one.","solutions":["Use a non-negative number; omit maxBuffer to get the 1 MiB default","Clamp computed values: maxBuffer: Math.max(0, n)","For big outputs pass a large finite value (e.g. 1024 * 1024 * 100) instead of any negative sentinel"],"exampleFix":"// before\nexecFile(\"ls\", [\"-la\"], { maxBuffer: quota - used }, cb);\n// after\nexecFile(\"ls\", [\"-la\"], { maxBuffer: Math.max(0, quota - used) }, cb);","handlingStrategy":"validation","validationCode":"const maxBuffer = Number(opts.maxBuffer ?? 1024 * 1024);\nif (!Number.isFinite(maxBuffer) || maxBuffer < 0) {\n  throw new RangeError(\"options.maxBuffer must be a finite number >= 0\");\n}\nopts = { ...opts, maxBuffer: Math.max(0, maxBuffer) };","typeGuard":"const isValidMaxBuffer = (n) => n == null || (Number.isFinite(n) && n >= 0);","tryCatchPattern":"try { execFile(file, args, opts, cb); }\ncatch (e) {\n  if (e.code === \"ERR_OUT_OF_RANGE\" && e.message.includes(\"maxBuffer\")) {\n    execFile(file, args, { ...opts, maxBuffer: 1024 * 1024 }, cb);\n  } else throw e;\n}","preventionTips":["Never encode 'unlimited' as a negative number — use a large finite value or omit it","Clamp every derived size with Math.max(0, n)","Handle runtime output-overflow (ERR_CHILD_PROCESS_STDIO_MAXBUFFER) separately from config validation"],"tags":["child-process","execfile","maxbuffer","range"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}