{"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":"validation","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_utils.ts#L95-L131","documentation":"validateIntegerRange(value, name, min, max) in ext/node/polyfills/_utils.ts is the shared validator for integer-typed options across node: polyfills (defaults are the signed 32-bit range). If value fails Number.isInteger it throws a plain Error \"${name} must be 'an integer' but was ${value}\" — note there is no error code, and the single quotes around 'an integer' are part of the literal message.","triggerScenarios":"Passing a float (1.5), NaN, Infinity, a numeric string ('1024'), or a numeric string from process.env directly to any integer-validated polyfill option that routes through this helper.","commonSituations":"Env vars (always strings) passed without Number() conversion; arithmetic producing floats (timeout / 1000 when timeout is not a multiple); JSON config storing numbers as strings.","solutions":["Convert before passing: Number.parseInt(value, 10) or Math.round(value)","Coerce env vars once at config load: port: Number(process.env.PORT)","Validate early with Number.isInteger(v) and fail with your own clear error message"],"exampleFix":"// before\nconfigure({ timeout: process.env.TIMEOUT }); // '5000' string → throws\n\n// after\nconst timeout = Number(process.env.TIMEOUT);\nif (!Number.isInteger(timeout)) throw new TypeError('TIMEOUT must be an integer');\nconfigure({ timeout });","handlingStrategy":"validation","validationCode":"function toIntOption(value: unknown, name: string, min?: number, max?: number): number {\n  const n = typeof value === 'number' ? value : Number(value);\n  if (!Number.isInteger(n)) throw new TypeError(`${name} must be an integer, got ${value}`);\n  if (min !== undefined && n < min) throw new RangeError(`${name} must be >= ${min}`);\n  if (max !== undefined && n > max) throw new RangeError(`${name} must be <= ${max}`);\n  return n;\n}\nconfigure({ timeout: toIntOption(process.env.TIMEOUT, 'timeout') });","typeGuard":"function isIntegerInRange(v: unknown, min = -2147483648, max = 2147483647): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= min && v <= max;\n}","tryCatchPattern":"try {\n  configure({ timeout: value as number });\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"must be 'an integer'\")) {\n    configure({ timeout: Math.round(Number(value)) });\n  } else throw err;\n}","preventionTips":["Convert env vars with Number() at the config boundary, never pass raw strings","Round or clamp divided values (e.g. ms→s conversions) before use","Type config fields as number and validate with Number.isInteger in a startup check"],"tags":["node-compat","validation","configuration","environment-variables"],"backgroundTag":"integer-range-validation","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"}