{"record":{"id":"d58a6adfdf2d7e7c","repo":"denoland/deno","slug":"err-invalid-arg-type-d58a6a","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"path\" argument must be of type string or an instance of Buffer. Received ${actual}","messagePattern":"The \"path\" argument must be of type string or an instance of Buffer\\. Received (.+?)","errorType":"exception","errorClass":"NodeTypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/fs/utils.mjs","lineNumber":281,"sourceCode":"      lazyPath().default.join(path, lazyPath().default.sep),\n    );\n    // Ignore lint. `concat` is a 'node:buffer' static method on `Buffer`\n    // deno-lint-ignore deno-internal/prefer-primordials\n    return Buffer.concat([pathBuffer, name]);\n  }\n\n  if (typeof path === \"string\" && typeof name === \"string\") {\n    // deno-lint-ignore deno-internal/prefer-primordials -- `join` is a `node:path` function\n    return lazyPath().default.join(path, name);\n  }\n\n  if (isUint8Array(path) && isUint8Array(name)) {\n    // Ignore lint. `concat` is a 'node:buffer' static method on `Buffer`\n    // deno-lint-ignore deno-internal/prefer-primordials\n    return Buffer.concat([path, bufferSep, name]);\n  }\n\n  throw new ERR_INVALID_ARG_TYPE(\n    \"path\",\n    [\"string\", \"Buffer\"],\n    path,\n  );\n}\n\nexport function getDirents(path, { 0: names, 1: types }, callback) {\n  let i;\n  if (typeof callback === \"function\") {\n    const len = names.length;\n    let toFinish = 0;\n    callback = once(callback);\n    for (i = 0; i < len; i++) {\n      const type = types[i];\n      if (type === UV_DIRENT_UNKNOWN) {\n        const name = names[i];\n        const idx = i;\n        toFinish++;","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/fs/utils.mjs#L263-L299","documentation":"The internal join helper that appends a directory-entry name to a base path accepts exactly two combinations: both arguments strings, or both Uint8Array/Buffer. A mixed pair (string + Buffer) or any other type matches neither branch and the helper throws ERR_INVALID_ARG_TYPE for the path argument. It backs readdir's dirent assembly, so type inconsistency between a base path and entry names is what surfaces it.","triggerScenarios":"Feeding readdir results back with mismatched types: a Buffer base path (encoding: 'buffer') combined with string names from another call, or the reverse; direct misuse of the internal join with heterogeneous arguments.","commonSituations":"Binary-safe path pipelines that convert only one side to Buffer; refactors that change one variable's type mid-pipeline; appending fs.Dirent names to a Buffer parent path.","solutions":["Make both operands the same type: path.toString('utf8') + name, or Buffer.concat([path, Buffer.from(name)]).","Consume fs.Dirent directly (readdir with withFileTypes) and build paths with a single type discipline.","Avoid Buffer paths unless NUL-byte-safe names are a hard requirement."],"exampleFix":"// before (mixed types)\nconst full = join(bufPath, stringName); // Buffer + string -> throws\n\n// after\nconst full = path.join(bufPath.toString('utf8'), stringName);\n// or stay binary\nconst full = Buffer.concat([bufPath, Buffer.from('/'), Buffer.from(stringName)]);","handlingStrategy":"type-guard","validationCode":"const sameType = (a, b) =>\n  (typeof a === 'string' && typeof b === 'string') ||\n  (a instanceof Uint8Array && b instanceof Uint8Array);\nif (!sameType(base, name)) {\n  throw new TypeError('path and name must both be strings or both Buffers');\n}","typeGuard":"function isHomogeneousPair(path, name) {\n  if (typeof path === 'string' && typeof name === 'string') return true;\n  if (path instanceof Uint8Array && name instanceof Uint8Array) return true;\n  return false;\n}","tryCatchPattern":null,"preventionTips":["Pick one path representation (string or Buffer) per module and stick to it.","Convert types at boundaries, never mid-pipeline.","Prefer readdir with withFileTypes to get consistent name/path types."],"tags":["filesystem","path","buffer","types","readdir"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}