{"record":{"id":"e551c259b5c0d4cd","repo":"denoland/deno","slug":"err-fs-cp-unknown","errorCode":"ERR_FS_CP_UNKNOWN","errorMessage":"Cannot copy an unknown file type","messagePattern":"Cannot copy an unknown file type","errorType":"exception","errorClass":"NodeSystemError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/cp/cp.ts","lineNumber":116,"sourceCode":"      });\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,\n        syscall: \"cp\",\n        errno: EINVAL,\n        code: \"EINVAL\",\n      });\n    case \"SYMLINK_TO_SUBDIRECTORY\":\n      throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EINVAL,\n        code: \"EINVAL\",\n      });\n    default:\n      throw err;\n  }\n}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_fs/cp/cp.ts#L98-L134","documentation":"ERR_FS_CP_UNKNOWN ('Cannot copy an unknown file type') is the fall-through in getStatsForCopy: when the stat bitmask from the native op matches none of the known source types (directory/file/char/block/symlink/socket/fifo), or when the native side reports kind 'UNKNOWN', the copy aborts rather than guessing. Typical source: a file whose type the stat call cannot classify in the current platform/permission context.","triggerScenarios":"Copying over filesystems that report exotic inode types (doors on illumos, whiteouts in overlayfs layers); stat succeeding but returning a type the flags enum does not cover.","commonSituations":"Reading inside container overlay layers or /proc-adjacent pseudo trees; cross-platform tooling hitting platform-specific file types.","solutions":["Narrow the copy to the files you know about (explicit list or filter on isFile/isDirectory)","Run the tool in an environment/user that can stat the tree normally, avoiding pseudo-filesystems","Wrap cp in try/catch on code ERR_FS_CP_UNKNOWN and report the path for manual handling"],"exampleFix":"// before\nawait fsp.cp(layerDir, outDir, { recursive: true }); // overlay whiteouts -> UNKNOWN\n\n// after\ntry {\n  await fsp.cp(layerDir, outDir, { recursive: true });\n} catch (err) {\n  if (err.code !== 'ERR_FS_CP_UNKNOWN') throw err;\n  // fall back: copy only regular files\n  await copyRegularFilesOnly(layerDir, outDir);\n}","handlingStrategy":"fallback","validationCode":"async function copyKnownTypesOnly(src, dest) {\n  for await (const e of fsp.opendir(src)) {\n    const st = await fsp.lstat(path.join(src, e.name));\n    if (st.isFile()) await fsp.copyFile(path.join(src, e.name), path.join(dest, e.name));\n    else if (st.isDirectory()) await copyKnownTypesOnly(path.join(src, e.name), path.join(dest, e.name));\n  }\n}","typeGuard":"function isKnownCopyType(st) {\n  return st.isFile() || st.isDirectory() || st.isSymbolicLink();\n}","tryCatchPattern":"try {\n  await fsp.cp(src, dest, { recursive: true });\n} catch (err) {\n  if (err.code !== 'ERR_FS_CP_UNKNOWN') throw err;\n  await copyKnownTypesOnly(src, dest); // copy only regular files/dirs\n}","preventionTips":["Avoid cp over pseudo/overlay filesystem trees","Scope copies to explicit allowlists of file types via filter","Log err.path from ERR_FS_CP_UNKNOWN to identify the offending entry"],"tags":["node-compat","fs","cp","unknown-type","filesystem"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}