{"record":{"id":"919460f4e1478bbe","repo":"denoland/deno","slug":"name-must-be-min-max-value-was","errorCode":null,"errorMessage":"${name} must be >= ${min} && <= ${max}. Value was ${value}","messagePattern":"(.+?) must be >= (.+?) && <= (.+?)\\. Value was (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_utils.ts","lineNumber":117,"sourceCode":"  for (; index + 1 < list.length; index++) {\n    list[index] = list[index + 1];\n  }\n  ArrayPrototypePop(list);\n}\n\nfunction validateIntegerRange(\n  value: number,\n  name: string,\n  min = -2147483648,\n  max = 2147483647,\n) {\n  // The defaults for min and max correspond to the limits of 32-bit integers.\n  if (!NumberIsInteger(value)) {\n    throw new Error(`${name} must be 'an integer' but was ${value}`);\n  }\n\n  if (value < min || value > max) {\n    throw new Error(\n      `${name} must be >= ${min} && <= ${max}. Value was ${value}`,\n    );\n  }\n}\n\ntype OptionalSpread<T> = T extends undefined ? []\n  : [T];\n\nfunction once<T = undefined>(\n  callback: (...args: OptionalSpread<T>) => void,\n) {\n  let called = false;\n  return function (this: unknown, ...args: OptionalSpread<T>) {\n    if (called) return;\n    called = true;\n    FunctionPrototypeApply(callback, this, args);\n  };\n}","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_utils.ts#L99-L135","documentation":"Thrown by the shared Node-compat validation helper validateIntegerRange in Deno's node polyfills (ext/node/polyfills/_utils.ts:105) when an integer option falls outside the allowed [min, max] bounds. The defaults (-2147483648..2147483647) mirror Node.js int32 validation, and the message echoes the exact bounds and offending value. It exists so Deno's node: polyfills reject out-of-range integer arguments with the same error text Node.js produces.","triggerScenarios":"Passing an integer-valued option to a node: API whose polyfill validates it with validateIntegerRange (or the Node counterpart it mirrors) — e.g. fs read/write lengths and offsets larger than the buffer or int32 range, negative values where a minimum of 0 is enforced, DNS family/socket option values outside the accepted set, or sizes/counts computed from user input that overflow 32-bit bounds. Note the value must already be an integer; non-integers fail the preceding Number.isInteger check and produce the companion 'must be an integer' error instead.","commonSituations":"Computing a byte length or offset from untrusted input (e.g. a parsed Content-Length header) and passing it to fs/buffer APIs without clamping; passing huge retry counts, timeouts, or ports; migrating code from environments where the argument was silently truncated; passing a numeric-looking string such as '1000' which fails earlier type checks or reaches range validation as a coerced out-of-range value.","solutions":["Read the message: it names the option, the exact min/max bounds, and the value that violated them — fix the source of that value (parse, clamp, or validate user input before the call).","Clamp the value to the documented range before calling the API: value = Math.max(min, Math.min(max, value)).","If the value legitimately exceeds int32 (e.g. a 5GB length), restructure the operation — split into multiple reads/writes or use an API variant that accepts larger values.","Add a unit test asserting your boundary values sit strictly inside the validated range so regressions surface at the source."],"exampleFix":"// before\nconst len = Number(req.headers['content-length']); // e.g. 5_000_000_000\nfs.readSync(fd, buf, 0, len, 0); // throws: length must be >= 0 && <= 2147483647\n\n// after\nconst len = Math.min(Number(req.headers['content-length']) || 0, buf.length);\nfs.readSync(fd, buf, 0, len, 0);","handlingStrategy":"validation","validationCode":"function clampInt(value, min, max, fallback = min) {\n  const n = Number(value);\n  if (!Number.isInteger(n)) return fallback;\n  return Math.max(min, Math.min(max, n));\n}\n// before calling the node: API\nconst length = clampInt(Number(header('content-length')), 0, buf.length);","typeGuard":"const isIntInRange = (v, min = -2147483648, max = 2147483647) =>\n  Number.isInteger(v) && v >= min && v <= max;","tryCatchPattern":"try {\n  fs.readSync(fd, buf, 0, length, 0);\n} catch (e) {\n  if (e instanceof RangeError || /must be >= .*&& <=/.test(e.message)) {\n    length = clampInt(length, 0, buf.length); // correct and let caller decide to retry\n  } else throw e;\n}","preventionTips":["Validate integer options at the trust boundary (HTTP headers, CLI args, config files) before they reach node: APIs.","Clamp lengths and offsets to the buffer's actual size rather than trusting computed values.","Centralize numeric option validation in one helper so bounds match the API's documented int32 limits."],"tags":["node-compat","argument-validation","range-check","integer","deno"],"backgroundTag":"argument-out-of-range","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}