{"record":{"id":"343051f047aa1c4c","repo":"denoland/deno","slug":"einval","errorCode":"EINVAL","errorMessage":"cannot copy a socket file: ${dest}","messagePattern":"cannot copy a socket file: (.+?)","errorType":"exception","errorClass":"ERR_FS_CP_SOCKET","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/cp/cp.ts","lineNumber":210,"sourceCode":"      errno: EISDIR,\n      code: \"EISDIR\",\n    });\n  } else if (\n    (statInfo & CpEntryFlags.IsSrcFile) ||\n    (statInfo & CpEntryFlags.IsSrcCharDevice) ||\n    (statInfo & CpEntryFlags.IsSrcBlockDevice)\n  ) {\n    return onFile(statInfo, src, dest, opts);\n  } else if (statInfo & CpEntryFlags.IsSrcSymlink) {\n    const isDestExists = !!(statInfo & CpEntryFlags.IsDestExists);\n    return onLink(isDestExists, src, dest, opts);\n  } else if (statInfo & CpEntryFlags.IsSrcSocket) {\n    throw new ERR_FS_CP_SOCKET({\n      message: `cannot copy a socket file: ${dest}`,\n      path: dest,\n      syscall: \"cp\",\n      errno: EINVAL,\n      code: \"EINVAL\",\n    });\n  } else if (statInfo & CpEntryFlags.IsSrcFifo) {\n    throw new ERR_FS_CP_FIFO_PIPE({\n      message: `cannot copy a FIFO pipe: ${dest}`,\n      path: dest,\n      syscall: \"cp\",\n      errno: EINVAL,\n      code: \"EINVAL\",\n    });\n  }\n  throw new ERR_FS_CP_UNKNOWN({\n    message: `cannot copy an unknown file type: ${dest}`,\n    path: dest,\n    syscall: \"cp\",\n    errno: EINVAL,\n    code: \"EINVAL\",\n  });\n}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_fs/cp/cp.ts#L192-L228","documentation":"Thrown by the JS slow path of Deno's cp polyfill when a copied entry is a unix-domain socket: 'cannot copy a socket file: <dest>' with code EINVAL (cp.ts:204-211). It fires during recursive copies whose options (filter, dereference, force: false, errorOnExist, preserveTimestamps, verbatimSymlinks, nonzero mode) disable the native fast path — see canUseNativeFastPath at cp.ts:168-176. The Rust fast path raises the equivalent ERR_FS_CP_SOCKET instead.","triggerScenarios":"fs.cp('/tmp', backup, { recursive: true, dereference: true }) walking into .X11-unix sockets; recursive filtered copies of runtime dirs containing docker.sock or an app's listening socket.","commonSituations":"Dev tooling that backs up project tmp/ dirs (Rails tmp/sockets/puma.sock); sandbox copies that include X11 or dbus sockets; docker-in-docker scripts copying /var/run.","solutions":["Extend your filter to skip sockets: inside filter, return false when (await lstat(src)).isSocket().","Name-based guard as a cheap alternative: filter: (s) => !s.endsWith('.sock').","Scope the copy to the data subdirectory instead of the runtime root that holds sockets."],"exampleFix":"// before\nawait fs.promises.cp('/tmp/app', '/backup/app', {\n  recursive: true,\n  filter: (s) => !s.includes('cache'),\n});\n// EINVAL: cannot copy a socket file: /backup/app/run.sock\n\n// after\nawait fs.promises.cp('/tmp/app', '/backup/app', {\n  recursive: true,\n  filter: async (s, d) =>\n    !s.includes('cache') && !(await fs.promises.lstat(s)).isSocket(),\n});","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nawait fs.promises.cp(srcDir, destDir, {\n  recursive: true,\n  filter: async (p) => {\n    const st = await fs.promises.lstat(p);\n    return !st.isSocket() && !st.isFIFO();\n  },\n});","typeGuard":null,"tryCatchPattern":"try {\n  await fs.promises.cp(a, b, { recursive: true, dereference: true });\n} catch (err) {\n  if (err.code === 'EINVAL' && /cannot copy a socket file/.test(err.message)) {\n    // rerun with a socket-skipping filter\n  } else throw err;\n}","preventionTips":["When you already pass a filter, extend it to reject sockets instead of only selecting files","Keep runtime sockets in a dedicated subdir and exclude that dir from copies","Check err.code === 'EINVAL' with syscall 'cp' — this throw path uses raw EINVAL, not ERR_FS_CP_SOCKET"],"tags":["deno","node-compat","fs","cp","unix-socket"],"backgroundTag":"unsupported-file-type","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"}