{"record":{"id":"080bd0b9f951e6d1","repo":"denoland/deno","slug":"err-invalid-arg-type-080bd0","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"fd\" argument must be of type number or an instance of FileHandle. Received ${fd}","messagePattern":"The \"fd\" argument must be of type number or an instance of FileHandle\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/http2.ts","lineNumber":3312,"sourceCode":"    }\n\n    if (\n      options.statCheck !== undefined &&\n      typeof options.statCheck !== \"function\"\n    ) {\n      throw new ERR_INVALID_ARG_VALUE(\"options.statCheck\", options.statCheck);\n    }\n\n    let streamOptions = 0;\n    if (options.waitForTrailers) {\n      streamOptions |= STREAM_OPTION_GET_TRAILERS;\n      this[kState].flags |= STREAM_FLAGS_HAS_TRAILERS;\n    }\n\n    if (ObjectPrototypeIsPrototypeOf(FsFileHandle.prototype, fd)) {\n      fd = fd.fd;\n    } else if (typeof fd !== \"number\") {\n      throw new ERR_INVALID_ARG_TYPE(\"fd\", [\"number\", \"FileHandle\"], fd);\n    }\n\n    debugStreamObj(this, \"initiating response from fd\");\n    this[kUpdateTimer]();\n    this.ownsFd = false;\n\n    const {\n      headers,\n      statusCode,\n    } = prepareResponseHeadersObject(headersParam, options);\n\n    setOtelServerStatus(this, statusCode);\n\n    // Payload/DATA frames are not permitted in these cases\n    if (\n      statusCode === HTTP_STATUS_NO_CONTENT ||\n      statusCode === HTTP_STATUS_RESET_CONTENT ||\n      statusCode === HTTP_STATUS_NOT_MODIFIED ||","sourceCodeStart":3294,"sourceCodeEnd":3330,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/http2.ts#L3294-L3330","documentation":"respondWithFD() accepts an fd that is either a raw numeric file descriptor or a FileHandle (from fs/promises open). Anything else — most commonly a file path string — throws ERR_INVALID_ARG_TYPE listing the accepted types.","triggerScenarios":"Passing a path string instead of an opened descriptor (confusing respondWithFD with respondWithFile); passing a closed or fake object without an fd property; passing a Deno FsFile where FileHandle.prototype check fails.","commonSituations":"Migrating code between respondWithFile and respondWithFD; using callback-style fs.open and passing the path 'by habit'; holding a FileHandle from a different fs surface whose prototype does not match.","solutions":["Use respondWithFile(path, ...) when you only have a path","Open the file first: const handle = await fs.promises.open(path, 'r'); then pass handle or handle.fd","Validate before the call: typeof fd === 'number' || (fd && typeof fd.fd === 'number')","Close the handle yourself afterwards — respondWithFD sets ownsFd = false and will not close it"],"exampleFix":"// before\nstream.respondWithFD(\"/srv/big.bin\", headers); // path string, not fd\n\n// after\nconst handle = await fs.promises.open(\"/srv/big.bin\", \"r\");\nstream.respondWithFD(handle, headers);\nstream.on(\"close\", () => handle.close());","handlingStrategy":"type-guard","validationCode":"if (typeof fd !== \"number\" && !(fd && typeof fd.fd === \"number\")) {\n  // you probably have a path: use respondWithFile instead\n  stream.respondWithFile(path, headers);\n  return;\n}","typeGuard":"function isFdLike(fd) {\n  return typeof fd === \"number\" || (typeof fd === \"object\" && fd !== null && typeof fd.fd === \"number\");\n}","tryCatchPattern":"try {\n  stream.respondWithFD(fd, headers);\n} catch (err) {\n  if (err.code === \"ERR_INVALID_ARG_TYPE\") { /* fall back to respondWithFile(path) */ }\n  throw err;\n}","preventionTips":["Have only a path? Use respondWithFile(path, ...). Have an open handle? Use respondWithFD(handle, ...)","Remember respondWithFD does not close your FileHandle — close it on stream close"],"tags":["http2","node-compat","argument-validation","file-serving","deno"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}