denoland/deno · error · SystemError
ERR_FS_CP_UNKNOWN
ERR_FS_CP_UNKNOWN
Error message
Cannot copy an unknown file type
What it means
If the source stat matches none of the known kinds (file, char/block device, symlink, socket, FIFO, directory), the native cp dispatch falls through to CpError::Unknown (kind 'UNKNOWN'), which throwCpError maps to ERR_FS_CP_UNKNOWN ('Cannot copy an unknown file type', errno EINVAL). fs.cp deliberately refuses anything it cannot classify so exotic entries are not silently dropped or mis-copied.
Solutions
- Enumerate and copy only entries you can classify: lstat each entry and skip/flag anything that is not file/dir/symlink
- Copy from a stable snapshot (tar the tree first) to avoid mid-copy type races
- Report the offending path from err.path and handle it specially instead of recursing blindly
Example fix
// before
fs.cp(mountPoint, 'out', { recursive: true }, cb); // unknown st_mode entry
// after — copy only classifiable entries
for (const name of fs.readdirSync(mountPoint)) {
const p = path.join(mountPoint, name);
const st = fs.lstatSync(p);
if (st.isFile() || st.isDirectory() || st.isSymbolicLink()) {
fs.cpSync(p, path.join('out', name), { recursive: true });
} else {
console.warn('skipping unclassifiable entry', p);
}
} Defensive patterns
Strategy: validation
Validate before calling
const copyable = (p) => { const st = fs.lstatSync(p); return st.isFile() || st.isDirectory() || st.isSymbolicLink(); }; Type guard
const isKnownCopyType = (st) => st.isFile() || st.isDirectory() || st.isSymbolicLink() || st.isCharacterDevice() || st.isBlockDevice();
Try / catch
try { await fs.promises.cp(src, dest, { recursive: true }); } catch (e) { if (e.code === 'ERR_FS_CP_UNKNOWN') { console.warn('unclassifiable entry', e.path); /* fall back to explicit per-entry copy */ } else throw e; } Prevention
- Don't recursive-copy pseudo-filesystems (/proc, /sys, FUSE mounts)
- Snapshot with tar first when entries may mutate mid-copy
- Whitelist entry kinds instead of assuming stat covers everything
When it happens
Trigger: Copying trees containing doors or event ports (Solaris-style IPC), weird FUSE/9p mount entries whose st_mode is unusual, or entries whose type changed between stat and dispatch; recursive copies over /proc- or /sys-backed paths on Linux.
Common situations: Container volume copies over pseudo-filesystems; cross-platform scripts hitting platform-specific file types; race conditions where an entry is replaced mid-copy (stat saw one kind, dispatch sees none of the known ones).
Related errors
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/e551c259b5c0d4cd.
Report an issue: GitHub.
Appendix: source
Thrown at ext/node/polyfills/_fs/cp/cp.ts:116
});
case "SOCKET":
throw new ERR_FS_CP_SOCKET({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
case "FIFO":
throw new ERR_FS_CP_FIFO_PIPE({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
case "UNKNOWN":
throw new ERR_FS_CP_UNKNOWN({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
case "SYMLINK_TO_SUBDIRECTORY":
throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
default:
throw err;
}
}View on GitHub (pinned to 9ad36f7a2c)