{"record":{"id":"4537506cfbd4732a","repo":"pydantic/monty","slug":"memoryusagelimit-must-be-a-non-negative-safe-integer","errorCode":null,"errorMessage":"memoryUsageLimit must be a non-negative safe integer","messagePattern":"memoryUsageLimit must be a non-negative safe integer","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/mountDir.ts","lineNumber":59,"sourceCode":"  readonly writeBytesLimit: number | null\n  readonly memoryUsageLimit: number\n  /** The opened host directory, shared by every feed this mount is passed to.\n   *  Symbol-keyed, so it stays off the public surface — see [`NATIVE_MOUNT`]. */\n  readonly [NATIVE_MOUNT]: NativeMountDir\n\n  constructor(options: MountDirOptions) {\n    const mode = options.mode ?? 'overlay'\n    // hasOwn, not `in`: prototype keys like 'toString' must not pass as modes\n    if (!Object.hasOwn(VALID_MODES, mode)) {\n      throw new Error(`invalid mount mode: '${mode}'. Expected 'read-only', 'read-write' or 'overlay'`)\n    }\n    this.hostPath = options.hostPath\n    this.virtualPath = options.virtualPath\n    this.mode = mode\n    this.writeBytesLimit = options.writeBytesLimit ?? null\n    this.memoryUsageLimit = options.memoryUsageLimit ?? DEFAULT_MEMORY_USAGE_LIMIT\n    if (!Number.isSafeInteger(this.memoryUsageLimit) || this.memoryUsageLimit < 0) {\n      throw new Error('memoryUsageLimit must be a non-negative safe integer')\n    }\n    // Opens the directory, so a bad host path throws here rather than at the\n    // first feed — and every feed then mounts this descriptor, which no rename\n    // of the host path can redirect.\n    this[NATIVE_MOUNT] = new NativeMountDir({\n      virtualPath: this.virtualPath,\n      hostPath: this.hostPath,\n      mode: this.mode,\n      memoryUsageLimit: this.memoryUsageLimit,\n      ...(this.writeBytesLimit !== null ? { writeBytesLimit: this.writeBytesLimit } : {}),\n    })\n  }\n\n  /** Releases the open host directory. Later feeds using this mount throw;\n   *  the properties above keep answering. Idempotent.\n   *\n   *  Only Windows needs this: it refuses to rename or delete a directory while\n   *  a handle to it is open, so a mount left open blocks the host from touching","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/mountDir.ts#L41-L77","documentation":"MountDir's memoryUsageLimit must be a non-negative Number safe integer (it bounds per-mount memory for overlay mounts). Values that are negative, fractional, NaN, or beyond Number.MAX_SAFE_INTEGER throw this Error in the constructor.","triggerScenarios":"new MountDir({ ..., memoryUsageLimit: -1 }), memoryUsageLimit: 1.5, a value parsed loosely from a string ('104857600' via Number on a malformed input giving NaN), or a limit in bytes exceeding 2**53-1.","commonSituations":"Limits computed by multiplying unvalidated numbers; parsing '100 MB' style strings; copying a byte limit expressed in a wider type from another language or config system.","solutions":["Pass a non-negative integer byte count, e.g. 100 * 1024 * 1024","Omit memoryUsageLimit to use DEFAULT_MEMORY_USAGE_LIMIT","Validate before constructing: Number.isSafeInteger(v) && v >= 0"],"exampleFix":"// before\nnew MountDir({ hostPath: './data', virtualPath: '/mnt/data', memoryUsageLimit: 1.5 });\n// after\nnew MountDir({ hostPath: './data', virtualPath: '/mnt/data', memoryUsageLimit: 100 * 1024 * 1024 });","handlingStrategy":"validation","validationCode":"function assertByteLimit(v) {\n  if (v !== undefined && (!Number.isSafeInteger(v) || v < 0)) {\n    throw new Error(`memoryUsageLimit must be a non-negative safe integer, got ${v}`);\n  }\n}\nassertByteLimit(opts.memoryUsageLimit);","typeGuard":"function isValidByteLimit(v) {\n  return v === undefined || (Number.isSafeInteger(v) && v >= 0);\n}","tryCatchPattern":"try {\n  const dir = new MountDir({ hostPath, virtualPath, memoryUsageLimit });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('memoryUsageLimit must be a non-negative safe integer')) {\n    throw new Error('memoryUsageLimit must be an integer byte count >= 0, e.g. 100 * 1024 * 1024');\n  }\n  throw e;\n}","preventionTips":["Express limits as integer byte counts built from Math.floor and integer multipliers","Parse size strings ('100MB') through a strict parser that yields safe integers","Omit the option to accept the library default when unsure"],"tags":["typescript","mount","memory-limit","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}