{"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":"exception","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/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_utils.ts#L99-L135","documentation":"The range half of validateIntegerRange (ext/node/polyfills/_utils.ts:117): the value is an integer but falls outside [min, max] (defaults to int32 bounds -2147483648..2147483647). Throws a plain Error '<name> must be >= <min> && <= <max>. Value was <value>'. Typical victims are lengths, positions, and sizes that exceed 2^31-1 when the API is backed by a 32-bit field.","triggerScenarios":"Passing 3e9 as a byte length or start position (exceeds int32 max); negative values where min is 0; reading a huge file with an offset larger than 2147483647 (files over 2 GiB).","commonSituations":"Large-file handling (>2 GiB) on APIs that take 32-bit positions; sizes computed in bytes from GB-scale products (e.g. 3 * 1024**3); port-like values passed to size arguments by argument mix-ups.","solutions":["Cap or chunk the operation so each call stays within int32 range (read huge files in segments)","Validate before the call: if (!(n >= 0 && n <= 0x7fffffff)) throw new RangeError(...) with your own message","Check whether the same result is available from an API taking Number/BigInt sized arguments"],"exampleFix":"// before\nfs.readSync(fd, buf, 0, 3 * 1024 ** 3, 0); // > int32 max\n\n// after\nconst CHUNK = 1 << 30;\nfor (let off = 0; off < size; off += CHUNK) {\n  fs.readSync(fd, buf, 0, Math.min(CHUNK, size - off), off);\n}","handlingStrategy":"validation","validationCode":"const MAX = 2147483647; if (!(Number.isInteger(n) && n >= 0 && n <= MAX)) throw new RangeError(`${name} out of int32 range`);","typeGuard":"function isInt32(n) { return Number.isInteger(n) && n >= -2147483648 && n <= 2147483647; }","tryCatchPattern":"try { api(n); } catch (e) { if (/must be >=/.test(e.message)) { /* chunk the operation */ } else throw e; }","preventionTips":["Chunk large reads/writes so each length/position stays under 2^31-1","Validate computed byte sizes against int32 bounds at the boundary"],"tags":["validation","range","int32","large-files"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}