{"record":{"id":"74ac32cceae4f24f","repo":"nodejs/node","slug":"memorycachestore-options-maxcount-must-be-a-non-ne","errorCode":null,"errorMessage":"MemoryCacheStore options.maxCount must be a non-negative integer","messagePattern":"MemoryCacheStore options\\.maxCount 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":44,"sourceCode":"  #hasEmittedMaxSizeEvent = false\n\n  /**\n   * @param {import('../../types/cache-interceptor.d.ts').default.MemoryCacheStoreOpts | undefined} [opts]\n   */\n  constructor (opts) {\n    super()\n    if (opts) {\n      if (typeof opts !== 'object') {\n        throw new TypeError('MemoryCacheStore options must be an object')\n      }\n\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' ||","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/cache/memory-cache-store.js#L26-L62","documentation":"Thrown by the MemoryCacheStore constructor when opts.maxCount is defined but is not a non-negative integer. maxCount caps the number of cached entries; the guard rejects floats, NaN, negative numbers, numeric strings, and Infinity.","triggerScenarios":"Passing maxCount: 1.5 (float), maxCount: -1, maxCount: '1000' (string), maxCount: NaN, or maxCount: Infinity.","commonSituations":"Reading the value from an env var as a string and not parsing/coercing; computing maxCount via division that yields a float; using Infinity to mean 'unlimited' (not allowed — omit the field instead).","solutions":["Pass a non-negative integer: { maxCount: 1000 }.","Parse and validate config values: Number.isInteger(Number(v)) ? Number(v) : undefined.","For 'unlimited', omit maxCount entirely rather than passing Infinity."],"exampleFix":"// before\nnew MemoryCacheStore({ maxCount: process.env.CACHE_COUNT }) // string\n\n// after\nconst maxCount = Number(process.env.CACHE_COUNT)\nnew MemoryCacheStore({\n  ...(Number.isInteger(maxCount) && maxCount >= 0 ? { maxCount } : {})\n})","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({ maxCount: optInt(config.count) })","typeGuard":"function isNonNegInt(v) { return Number.isInteger(v) && v >= 0 }","tryCatchPattern":null,"preventionTips":["Parse env/config values with Number() and validate Number.isInteger && >= 0.","Omit maxCount for unlimited instead of passing Infinity.","Centralize cache config validation in one helper."],"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"}