{"record":{"id":"d3bbd8e218fd4d64","repo":"denoland/deno","slug":"err-fs-cp-socket","errorCode":"ERR_FS_CP_SOCKET","errorMessage":"Cannot copy a socket file","messagePattern":"Cannot copy a socket file","errorType":"exception","errorClass":"SystemError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/cp/cp.ts","lineNumber":100,"sourceCode":"      });\n    case \"EEXIST\":\n      throw new ERR_FS_CP_EEXIST({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EEXIST,\n        code: \"EEXIST\",\n      });\n    case \"EISDIR\":\n      throw new ERR_FS_EISDIR({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EISDIR,\n        code: \"EISDIR\",\n      });\n    case \"SOCKET\":\n      throw new ERR_FS_CP_SOCKET({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EINVAL,\n        code: \"EINVAL\",\n      });\n    case \"FIFO\":\n      throw new ERR_FS_CP_FIFO_PIPE({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EINVAL,\n        code: \"EINVAL\",\n      });\n    case \"UNKNOWN\":\n      throw new ERR_FS_CP_UNKNOWN({\n        message: err.message,\n        path: err.path,","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_fs/cp/cp.ts#L82-L118","documentation":"During copy dispatch, if the source stat reports a socket, fs.cp rejects with CpError::Socket (kind 'SOCKET'), mapped by throwCpError to ERR_FS_CP_SOCKET ('Cannot copy a socket file', errno EINVAL). Unix domain sockets hold no persistent content — they are a rendezvous endpoint — so copying their directory entry is meaningless and refused.","triggerScenarios":"fs.cp on /run or /var/run trees (or any dir) containing *.sock files with { recursive: true }; containerizing a volume that includes a live database socket (postgres/.s.PGSQL.5432, docker.sock); archiving a node_modules/.cache directory that contains IPC sockets.","commonSituations":"Recursive backup/copy scripts sweeping system directories; CI copying a runtime state directory; Docker/K8v volume mirroring where daemons left sockets behind.","solutions":["Exclude socket entries: filter with fs.lstat + stats.isSocket() (or use glob exclude) before copying","Clean the source tree of runtime sockets before archiving (sockets are recreated by their daemons)","If you only need regular files, copy with a filter callback: { recursive: true, filter: (s) => !s.endsWith('.sock') }"],"exampleFix":"// before\nfs.cp('/var/run/app', 'backup', { recursive: true }, cb); // hits a .sock file\n\n// after\nfs.cp('/var/run/app', 'backup', {\n  recursive: true,\n  filter: (src) => !fs.statSync(src).isSocket(),\n}, cb);","handlingStrategy":"validation","validationCode":"const skipSockets = (src) => { const st = fs.lstatSync(src); return st.isDirectory() || st.isFile() || st.isSymbolicLink(); };","typeGuard":"const isCopyableEntry = (st) => st.isFile() || st.isDirectory() || st.isSymbolicLink();","tryCatchPattern":"try { await fs.promises.cp(src, dest, { recursive: true, filter: isCopyablePath }); } catch (e) { if (e.code === 'ERR_FS_CP_SOCKET') { /* exclude *.sock and retry once */ } else throw e; }","preventionTips":["Never recursive-copy /run, /var/run, or live daemon state dirs","Use a filter that whitelists file kinds rather than blacklisting paths","Sockets are recreated by daemons — just exclude them from backups"],"tags":["node-compat","fs","cp","copy","socket","err-fs-cp-socket","unix","deno"],"backgroundTag":"fs-cp-unsupported-file-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}