Skip to content

Commit 00a86fe

Browse files
fs: fix cp dir/non-dir mismatch error messages
The error messages for `ERR_FS_CP_DIR_TO_NON_DIR` and `ERR_FS_CP_NON_DIR_TO_DIR` were the inverse of the copy direction actually performed. Refs: #44598 (comment) PR-URL: #53150 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent 88d0701 commit 00a86fe

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/internal/errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1204,12 +1204,12 @@ E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
12041204
', which is being used to run Node.js',
12051205
TypeError);
12061206
E('ERR_FS_CP_DIR_TO_NON_DIR',
1207-
'Cannot overwrite directory with non-directory', SystemError);
1207+
'Cannot overwrite non-directory with directory', SystemError);
12081208
E('ERR_FS_CP_EEXIST', 'Target already exists', SystemError);
12091209
E('ERR_FS_CP_EINVAL', 'Invalid src or dest', SystemError);
12101210
E('ERR_FS_CP_FIFO_PIPE', 'Cannot copy a FIFO pipe', SystemError);
12111211
E('ERR_FS_CP_NON_DIR_TO_DIR',
1212-
'Cannot overwrite non-directory with directory', SystemError);
1212+
'Cannot overwrite directory with non-directory', SystemError);
12131213
E('ERR_FS_CP_SOCKET', 'Cannot copy a socket file', SystemError);
12141214
E('ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY',
12151215
'Cannot overwrite symlink in subdirectory of self', SystemError);

lib/internal/fs/cp/cp-sync.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function checkPathsSync(src, dest, opts) {
8282
}
8383
if (srcStat.isDirectory() && !destStat.isDirectory()) {
8484
throw new ERR_FS_CP_DIR_TO_NON_DIR({
85-
message: `cannot overwrite directory ${src} ` +
86-
`with non-directory ${dest}`,
85+
message: `cannot overwrite non-directory ${dest} ` +
86+
`with directory ${src}`,
8787
path: dest,
8888
syscall: 'cp',
8989
errno: EISDIR,
@@ -92,8 +92,8 @@ function checkPathsSync(src, dest, opts) {
9292
}
9393
if (!srcStat.isDirectory() && destStat.isDirectory()) {
9494
throw new ERR_FS_CP_NON_DIR_TO_DIR({
95-
message: `cannot overwrite non-directory ${src} ` +
96-
`with directory ${dest}`,
95+
message: `cannot overwrite directory ${dest} ` +
96+
`with non-directory ${src}`,
9797
path: dest,
9898
syscall: 'cp',
9999
errno: ENOTDIR,

lib/internal/fs/cp/cp.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ async function checkPaths(src, dest, opts) {
8686
}
8787
if (srcStat.isDirectory() && !destStat.isDirectory()) {
8888
throw new ERR_FS_CP_DIR_TO_NON_DIR({
89-
message: `cannot overwrite directory ${src} ` +
90-
`with non-directory ${dest}`,
89+
message: `cannot overwrite non-directory ${dest} ` +
90+
`with directory ${src}`,
9191
path: dest,
9292
syscall: 'cp',
9393
errno: EISDIR,
@@ -96,8 +96,8 @@ async function checkPaths(src, dest, opts) {
9696
}
9797
if (!srcStat.isDirectory() && destStat.isDirectory()) {
9898
throw new ERR_FS_CP_NON_DIR_TO_DIR({
99-
message: `cannot overwrite non-directory ${src} ` +
100-
`with directory ${dest}`,
99+
message: `cannot overwrite directory ${dest} ` +
100+
`with non-directory ${src}`,
101101
path: dest,
102102
syscall: 'cp',
103103
errno: ENOTDIR,

0 commit comments

Comments
 (0)