{"record":{"id":"7cfce03029b3e1ee","repo":"pydantic/monty","slug":"invalid-mount-mode-mode-expected-read-only-read-write-or","errorCode":null,"errorMessage":"invalid mount mode: '${mode}'. Expected 'read-only', 'read-write' or 'overlay'","messagePattern":"invalid mount mode: '(.+?)'\\. Expected 'read-only', 'read-write' or 'overlay'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/mountDir.ts","lineNumber":51,"sourceCode":" * const mount = new MountDir({ hostPath: '/path/on/host', virtualPath: '/mnt/data', mode: 'read-only' })\n * await session.feedRun(\"open('/mnt/data/file.txt').read()\", { mount })\n * ```\n */\nexport class MountDir {\n  readonly hostPath: string\n  readonly virtualPath: string\n  readonly mode: MountDirMode\n  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 } : {}),","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/mountDir.ts#L33-L69","documentation":"MountDir's mode option must be one of 'read-only', 'read-write' or 'overlay' (defaulting to 'overlay'). The constructor validates with Object.hasOwn against a whitelist — so prototype-inherited keys like 'toString' are also rejected — and throws this Error for anything else, before any directory is opened.","triggerScenarios":"new MountDir({ hostPath, virtualPath, mode: 'rw' }) or any misspelled/aliased mode ('readonly', 'RO', 'write').","commonSituations":"Mode strings sourced from config files or environment variables with different naming conventions; abbreviations assumed supported; camelCase vs kebab-case confusion.","solutions":["Use exactly 'read-only', 'read-write' or 'overlay' (or omit mode for the 'overlay' default)","Normalize config-sourced modes to the kebab-case literals before constructing MountDir","Map your app's own mode enum to the library's three valid values"],"exampleFix":"// before\nnew MountDir({ hostPath: './data', virtualPath: '/mnt/data', mode: 'readonly' });\n// after\nnew MountDir({ hostPath: './data', virtualPath: '/mnt/data', mode: 'read-only' });","handlingStrategy":"validation","validationCode":"const MOUNT_MODES = new Set(['read-only', 'read-write', 'overlay']);\nif (mode !== undefined && !MOUNT_MODES.has(mode)) {\n  throw new Error(`mode must be 'read-only', 'read-write' or 'overlay', got ${JSON.stringify(mode)}`);\n}","typeGuard":"function isMountMode(v) {\n  return v === undefined || v === 'read-only' || v === 'read-write' || v === 'overlay';\n}","tryCatchPattern":"try {\n  const dir = new MountDir({ hostPath, virtualPath, mode });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('invalid mount mode')) {\n    throw new Error(`fix mount mode in config; valid values: read-only, read-write, overlay`);\n  }\n  throw e;\n}","preventionTips":["Use the exact kebab-case literals 'read-only', 'read-write', 'overlay'","Omit mode when the 'overlay' default is what you want","Validate config/env-sourced mode strings at startup"],"tags":["typescript","mount","invalid-enum","configuration"],"backgroundTag":"invalid-enum-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"}