{"record":{"id":"df52d4c5a6daaae3","repo":"denoland/deno","slug":"err-method-not-implemented-df52d4","errorCode":"ERR_METHOD_NOT_IMPLEMENTED","errorMessage":"The open() method is not implemented","messagePattern":"The open\\(\\) method is not implemented","errorType":"exception","errorClass":"NodeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/fs/streams.mjs","lineNumber":112,"sourceCode":"        if (er) {\n          callback(er);\n        } else {\n          stream.fd = fd;\n          callback();\n          stream.emit(\"open\", stream.fd);\n          stream.emit(\"ready\");\n        }\n      },\n    );\n  }\n}\n/**\n * @param {import(\"node:fs/promises\").FileHandle} handle\n */\nconst FileHandleOperations = (handle) => {\n  return {\n    open: (_path, _flags, _mode, _cb) => {\n      throw new ERR_METHOD_NOT_IMPLEMENTED(\"open()\");\n    },\n    close: (_fd, cb) => {\n      handle[kUnref]();\n      PromisePrototypeThen(handle.close(), () => cb(), cb);\n    },\n    fsync: (_fd, cb) => {\n      PromisePrototypeThen(handle.sync(), () => cb(), cb);\n    },\n    read: (_fd, buf, offset, length, pos, cb) => {\n      PromisePrototypeThen(\n        handle.read(buf, offset, length, pos),\n        // deno-lint-ignore deno-internal/prefer-primordials\n        (r) => cb(null, r.bytesRead, r.buffer),\n        (err) => cb(err, 0, buf),\n      );\n    },\n    write: (_fd, buf, offset, length, pos, cb) => {\n      PromisePrototypeThen(","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/fs/streams.mjs#L94-L130","documentation":"When fs.createReadStream/fs.createWriteStream are built over an existing FileHandle (options.fd), the stream's internal fs-operation table is swapped for FileHandleOperations, whose open() entry always throws ERR_METHOD_NOT_IMPLEMENTED: the file is already open, so there is nothing to reopen. The normal stream lifecycle never calls it (stream.fd is already a number and _construct short-circuits), so this error means code explicitly drove the open path on a handle-based stream.","triggerScenarios":"Monkey-patching or calling stream.open on a stream created with { fd: fileHandle }; a generic stream wrapper that unconditionally invokes open on every stream; re-triggering construction/open after autoClose set stream.fd back to null; test harnesses that force-open all streams regardless of construction.","commonSituations":"Porting path-based stream code to fd-based without removing the manual open call; graceful-fs-style wrapper libraries that patch open across all streams; reopen-on-error retry logic that does not know the stream was handle-backed.","solutions":["Do not call open on fd-based streams; the handle is already open","Pass a path instead of a handle if you need open semantics: fs.createReadStream(path, opts)","In wrappers, skip open when the fd is already set: if (stream.fd == null) stream.open()","Catch ERR_METHOD_NOT_IMPLEMENTED in generic drivers as the signal that a stream is handle-backed, and treat it as already-open"],"exampleFix":"// before\nfunction ensureOpen(stream) {\n  stream.open(); // throws for createReadStream(null, { fd: handle })\n}\n\n// after\nfunction ensureOpen(stream) {\n  if (stream.fd == null) stream.open(); // fd already set => handle-backed, skip\n}","handlingStrategy":"validation","validationCode":"function ensureOpen(stream) {\n  // fd already assigned => stream was built on an fd/FileHandle; open() is intentionally unimplemented\n  if (stream.fd == null && typeof stream.open === 'function') stream.open();\n}","typeGuard":"const isHandleBacked = (stream) => Number.isInteger(stream.fd) && (stream.path === undefined || stream.path === null);","tryCatchPattern":"try { stream.open(); } catch (e) { if (e?.code === 'ERR_METHOD_NOT_IMPLEMENTED') return; // already open via FileHandle; nothing to do\n throw e; }","preventionTips":["Treat fd-based streams as pre-opened: check stream.fd before any open call","Choose path-based createReadStream when your wrapper needs open semantics","Do not monkey-patch open() on handle-backed streams"],"tags":["fs","streams","filehandle","not-implemented","node-compat","deno"],"backgroundTag":"method-not-implemented","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}