{"record":{"id":"5873f6313dc85732","repo":"denoland/deno","slug":"name-must-be-an-integer-but-was-value","errorCode":null,"errorMessage":"${name} must be 'an integer' but was ${value}","messagePattern":"(.+?) must be 'an integer' but was (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_utils.ts","lineNumber":113,"sourceCode":"  );\n}\n\nfunction spliceOne(list: string[], index: number) {\n  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;","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_utils.ts#L95-L131","documentation":"validateIntegerRange in Deno's node internal utils (ext/node/polyfills/_utils.ts:113) throws a plain Error '<name> must be 'an integer' but was <value>' when the value is not an integer (NaN, Infinity, fractional, or numeric strings). Unlike Node's validateInt32/validateInteger, this shim throws uncoded Errors and does not accept string coercion, so values like '1024' fail where Node code may have expected tolerance.","triggerScenarios":"Passing 0.5, NaN, or '42' (string) to an option validated by this shim; NaN produced by parseInt(undefined) or a failed Number conversion feeding into a byteLength/position argument.","commonSituations":"Options parsed from CLI args or env vars without Number() conversion; NaN from Number(null)-adjacent bugs or parseInt of a string without a numeric prefix; fractional sizes from unit-conversion math (KB -> bytes dividing incorrectly).","solutions":["Coerce explicitly and validate before the call: const n = Number(v); if (!Number.isInteger(n)) throw ...","For env/CLI strings, wrap with Number.parseInt(v, 10) and check Number.isNaN first","Round computed sizes with Math.ceil() when fractional values arise from arithmetic"],"exampleFix":"// before\nstream.readSome({ length: parseInt(maybeUndefined) }); // NaN\n\n// after\nconst length = Number.parseInt(input, 10);\nif (!Number.isInteger(length)) throw new TypeError('length must be an integer');\nstream.readSome({ length });","handlingStrategy":"validation","validationCode":"const n = Number(value); if (!Number.isInteger(n)) throw new TypeError(`${name} must be an integer`);","typeGuard":"function isSafeInt(v) { return Number.isInteger(v); }","tryCatchPattern":"try { api({ size }); } catch (e) { if (/must be 'an integer'/.test(e.message)) { size = Math.ceil(size); return api({ size }); } throw e; }","preventionTips":["Convert env/CLI strings with Number() before passing","Check Number.isNaN after parseInt; never pass unvalidated parses to numeric options"],"tags":["validation","integer","deno-compat","arguments"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}