{"record":{"id":"949920633111445d","repo":"nodejs/node","slug":"memorycachestore-options-maxsize-must-be-a-non-neg","errorCode":null,"errorMessage":"MemoryCacheStore options.maxSize must be a non-negative integer","messagePattern":"MemoryCacheStore options\\.maxSize must be a non-negative integer","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/cache/memory-cache-store.js","lineNumber":55,"sourceCode":"\n      if (opts.maxCount !== undefined) {\n        if (\n          typeof opts.maxCount !== 'number' ||\n          !Number.isInteger(opts.maxCount) ||\n          opts.maxCount < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxCount must be a non-negative integer')\n        }\n        this.#maxCount = opts.maxCount\n      }\n\n      if (opts.maxSize !== undefined) {\n        if (\n          typeof opts.maxSize !== 'number' ||\n          !Number.isInteger(opts.maxSize) ||\n          opts.maxSize < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxSize must be a non-negative integer')\n        }\n        this.#maxSize = opts.maxSize\n      }\n\n      if (opts.maxEntrySize !== undefined) {\n        if (\n          typeof opts.maxEntrySize !== 'number' ||\n          !Number.isInteger(opts.maxEntrySize) ||\n          opts.maxEntrySize < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxEntrySize must be a non-negative integer')\n        }\n        this.#maxEntrySize = opts.maxEntrySize\n      }\n    }\n  }\n\n  /**","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/cache/memory-cache-store.js#L37-L73","documentation":"Thrown by the MemoryCacheStore constructor when opts.maxSize is defined but is not a non-negative integer. maxSize caps the total cached body size in bytes (default 100 MB / 104857600). Floats, negatives, strings, NaN, and Infinity are rejected.","triggerScenarios":"Passing maxSize: 50 * 1024 * 1024.5 (float bytes), maxSize: -1, maxSize: '104857600' (string), or maxSize: Infinity.","commonSituations":"Configuring size in MB and multiplying by a float KB factor; reading from env as a string; using Infinity for unlimited (disallowed — omit instead).","solutions":["Pass a non-negative integer byte count: { maxSize: 100 * 1024 * 1024 }.","Compute sizes with integer arithmetic and validate with Number.isInteger.","For 'unlimited', omit maxSize."],"exampleFix":"// before\nnew MemoryCacheStore({ maxSize: '104857600' })\n\n// after\nnew MemoryCacheStore({ maxSize: 100 * 1024 * 1024 })","handlingStrategy":"validation","validationCode":"function optInt(v) {\n  const n = Number(v)\n  if (!Number.isInteger(n) || n < 0) throw new TypeError('must be a non-negative integer')\n  return n\n}\n// new MemoryCacheStore({ maxSize: optInt(config.sizeBytes) })","typeGuard":"function isNonNegInt(v) { return Number.isInteger(v) && v >= 0 }","tryCatchPattern":null,"preventionTips":["Express sizes in integer bytes (use integer MB * 1024 * 1024).","Validate Number.isInteger before assigning maxSize.","Omit maxSize for the default 100 MB rather than passing Infinity."],"tags":["undici","cache","memory-cache-store","validation","configuration"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}