{"record":{"id":"382df5b7f22a89a7","repo":"pydantic/monty","slug":"update-modes-are-not-yet-supported","errorCode":null,"errorMessage":"update modes ('+') are not yet supported","messagePattern":"update modes \\('\\+'\\) are not yet supported","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/types.ts","lineNumber":141,"sourceCode":"  }\n\n  let action: string | undefined\n  let binary = false\n  let text = false\n  for (const char of mode) {\n    if (char === 'r' || char === 'w' || char === 'a') {\n      if (action !== undefined) throw new TypeError('must have exactly one of create/read/write/append mode')\n      action = char\n    } else if (char === 'x') {\n      throw new TypeError('exclusive creation mode is not supported')\n    } else if (char === 'b') {\n      if (binary) throw new TypeError('invalid mode: binary mode specified twice')\n      binary = true\n    } else if (char === 't') {\n      if (text) throw new TypeError('invalid mode: text mode specified twice')\n      text = true\n    } else if (char === '+') {\n      throw new TypeError(\"update modes ('+') are not yet supported\")\n    } else {\n      throw new TypeError(`invalid mode: '${char}'`)\n    }\n  }\n  if (binary && text) throw new TypeError(\"can't have text and binary mode at once\")\n  if (action === undefined) {\n    throw new TypeError('Must have exactly one of create/read/write/append mode and at most one plus')\n  }\n  return `${action}${binary ? 'b' : ''}`\n}\n\n/** Validates that a file position can cross the JavaScript boundary exactly. */\nexport function validateFilePosition(position: unknown): asserts position is number {\n  if (typeof position !== 'number' || !Number.isSafeInteger(position) || position < 0) {\n    throw new TypeError('MontyFileHandle position must be a non-negative safe integer')\n  }\n}\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/types.ts#L123-L159","documentation":"The mode string contained '+', requesting read/update (e.g. 'r+', 'w+'). Update modes are not yet implemented in the JS bindings' file handling, so they are rejected eagerly with a TypeError rather than silently misbehaving.","triggerScenarios":"Calling MontyFileHandle's constructor or pushFileHandle with any mode containing '+': 'r+', 'w+', 'a+', 'rb+', etc.","commonSituations":"Porting Python code that opens files read-write with 'r+' to patch bytes in place; developers expecting seek-and-write on an open handle.","solutions":["Split into two operations: read the file (mode 'r'), then rewrite it (mode 'w' or 'a')","If read-modify-write is needed, read full content, modify in memory, and write back with 'w'","Use append ('a') if you only need to add to the file"],"exampleFix":"// before\nconst fh = new MontyFileHandle(path, 'r+')\n// after\nconst data = new MontyFileHandle(path, 'r').read()\nnew MontyFileHandle(path, 'w').write(transform(data))","handlingStrategy":"validation","validationCode":"if (typeof mode === 'string' && mode.includes('+')) throw new Error('update modes not supported by monty-js file handles')","typeGuard":"function isNonUpdateMode(mode) { return typeof mode === 'string' && /^[rwa][bt]?$/.test(mode) }","tryCatchPattern":"try { fh = new MontyFileHandle(path, mode) } catch (e) { if (e instanceof TypeError && e.message.includes(\"not yet supported\")) { /* fall back to read-then-write */ } else throw e }","preventionTips":["Never use '+' modes; implement read-modify-write as separate open/read then open/write steps","Document the supported mode subset for your team","Check limitations docs before porting CPython file code"],"tags":["typescript","file-mode","feature-gap"],"backgroundTag":"operation-not-supported","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"}