{"record":{"id":"703bc329ddb822a7","repo":"expressjs/multer","slug":"expected-limits-key-to-be-a-non-negative-i","errorCode":null,"errorMessage":"Expected limits.' + key + ' to be a non-negative integer or Infinity","messagePattern":"Expected limits\\.' \\+ key \\+ ' to be a non-negative integer or Infinity","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/validate-limits.js","lineNumber":10,"sourceCode":"// busboy compares most limits with strict equality, so a non-integer value\n// never matches and silently disables the limit. Reject such values up front.\nfunction validateLimits (limits) {\n  Object.keys(limits).forEach(function (key) {\n    var value = limits[key]\n\n    if (value == null) return\n    if ((Number.isInteger(value) && value >= 0) || value === Infinity) return\n\n    throw new TypeError('Expected limits.' + key + ' to be a non-negative integer or Infinity')\n  })\n}\n\nmodule.exports = validateLimits\n","sourceCodeStart":1,"sourceCodeEnd":15,"githubUrl":"https://github.com/expressjs/multer/blob/a53296bbd6d57349bcf56da3b2de5111e1c87c54/lib/validate-limits.js#L1-L15","documentation":"This TypeError is thrown by the limits validation helper when a value passed in the `limits` options object is not a non-negative integer or Infinity. The library requires every provided limit (e.g. concurrency, queue limits) to be a whole number >= 0 or Infinity so downstream counting logic cannot break; null/undefined values are allowed (treated as unset), but anything else fails fast at configuration time rather than causing subtle runtime bugs.","triggerScenarios":"Calling the module's constructor/setup with a `limits` object containing a key whose value is a negative integer (e.g. -1), a non-integer number (e.g. 1.5, NaN), a numeric string (e.g. '10' from a CLI arg or env var), a boolean, an object, or a value parsed incorrectly from JSON.","commonSituations":"Passing process.env values (strings) directly into limits without Number() parsing; using parseInt on malformed input yielding NaN; defaulting limits to -1 to mean 'unlimited' instead of Infinity; copying limits from another library whose sentinel for unlimited is -1 or 0.","solutions":["Convert any string values from env vars/CLI args to numbers with Number() and validate with Number.isInteger before passing them.","Replace negative sentinel values like -1 with Infinity to mean unlimited.","Check for non-integer values (decimals, NaN) and round, floor, or fix the source value.","Remove keys with invalid values if the limit is intentionally unset (null/undefined are accepted)."],"exampleFix":"// before\nconst pool = createPool({ limits: { concurrency: process.env.CONCURRENCY } })\n// after\nconst concurrency = Number(process.env.CONCURRENCY)\nconst pool = createPool({ limits: { concurrency: concurrency > 0 ? concurrency : Infinity } })","handlingStrategy":"validation","validationCode":"function validateLimits(limits) {\n  for (const [key, value] of Object.entries(limits)) {\n    if (value == null) continue\n    if ((Number.isInteger(value) && value >= 0) || value === Infinity) continue\n    throw new TypeError('Expected limits.' + key + ' to be a non-negative integer or Infinity')\n  }\n}","typeGuard":"function isValidLimit(value) {\n  return value == null || (Number.isInteger(value) && value >= 0) || value === Infinity\n}","tryCatchPattern":"try {\n  createPool({ limits })\n} catch (err) {\n  if (err instanceof TypeError && err.message.startsWith('Expected limits.')) {\n    console.error('Invalid limits config:', err.message)\n    process.exit(1)\n  }\n  throw err\n}","preventionTips":["Always parse env-var/CLI limit values with Number() and validate with Number.isInteger before use.","Use Infinity (not -1 or 0) as the sentinel for unlimited.","Coerce with Math.floor when a computed limit could be fractional.","Run config validation at startup, before constructing the pool/client.","Add a unit test asserting every configured limit passes isValidLimit."],"tags":["validation","typeerror","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"a53296bbd6d57349bcf56da3b2de5111e1c87c54","analyzedAt":"2026-09-01T01:03:06.481Z","contentChangedAt":"2026-09-01T01:03:06.481Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}