fs: fix error codes for fs.cp

The context passed into this error must have `.code`, `.syscall` and
`.message`.

Fixes: https://github.com/nodejs/node/issues/41104

PR-URL: https://github.com/nodejs/node/pull/41106
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Antoine du Hamel authored and Danielle Adams committed 2022-01-31 23:08:54 -05:00
1 parent 67c6170dc7
commit eaab8d0498
3 files changed
+27 -1

No files matched your search

+2
View File
@@ -25,6 +25,8 @@ rules:
message: "Please use `require('internal/errors').hideStackFrames()` instead."
- selector: "AssignmentExpression:matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])"
message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'."
- selector: "ThrowStatement > NewExpression[callee.name=/^ERR_[A-Z_]+$/] > ObjectExpression:first-child:not(:has([key.name='message']):has([key.name='code']):has([key.name='syscall']))"
message: "The context passed into SystemError constructor must have .code, .syscall and .message."
no-restricted-globals:
- error
- name: AbortController
+12
View File
@@ -70,6 +70,7 @@ function checkPathsSync(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
if (srcStat.isDirectory() && !destStat.isDirectory()) {
@@ -79,6 +80,7 @@ function checkPathsSync(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EISDIR,
code: 'EISDIR',
});
}
if (!srcStat.isDirectory() && destStat.isDirectory()) {
@@ -88,6 +90,7 @@ function checkPathsSync(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: ENOTDIR,
code: 'ENOTDIR',
});
}
}
@@ -98,6 +101,7 @@ function checkPathsSync(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return { srcStat, destStat };
@@ -135,6 +139,7 @@ function checkParentPathsSync(src, srcStat, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return checkParentPathsSync(src, srcStat, destParent);
@@ -170,6 +175,7 @@ function getStats(destStat, src, dest, opts) {
path: src,
syscall: 'cp',
errno: EINVAL,
code: 'EISDIR',
});
} else if (srcStat.isFile() ||
srcStat.isCharacterDevice() ||
@@ -183,6 +189,7 @@ function getStats(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
} else if (srcStat.isFIFO()) {
throw new ERR_FS_CP_FIFO_PIPE({
@@ -190,6 +197,7 @@ function getStats(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
throw new ERR_FS_CP_UNKNOWN({
@@ -197,6 +205,7 @@ function getStats(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
@@ -215,6 +224,7 @@ function mayCopyFile(srcStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EEXIST,
code: 'EEXIST',
});
}
}
@@ -305,6 +315,7 @@ function onLink(destStat, src, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
// Prevent copy if src is a subdir of dest since unlinking
@@ -316,6 +327,7 @@ function onLink(destStat, src, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return copyLink(resolvedSrc, dest);
+13 -1
View File
@@ -82,6 +82,7 @@ async function checkPaths(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
if (srcStat.isDirectory() && !destStat.isDirectory()) {
@@ -91,6 +92,7 @@ async function checkPaths(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EISDIR,
code: 'EISDIR',
});
}
if (!srcStat.isDirectory() && destStat.isDirectory()) {
@@ -100,6 +102,7 @@ async function checkPaths(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: ENOTDIR,
code: 'ENOTDIR',
});
}
}
@@ -110,6 +113,7 @@ async function checkPaths(src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return { srcStat, destStat };
@@ -171,6 +175,7 @@ async function checkParentPaths(src, srcStat, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return checkParentPaths(src, srcStat, destParent);
@@ -209,7 +214,8 @@ async function getStatsForCopy(destStat, src, dest, opts) {
message: `${src} is a directory (not copied)`,
path: src,
syscall: 'cp',
errno: EINVAL,
errno: EISDIR,
code: 'EISDIR',
});
} else if (srcStat.isFile() ||
srcStat.isCharacterDevice() ||
@@ -223,6 +229,7 @@ async function getStatsForCopy(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
} else if (srcStat.isFIFO()) {
throw new ERR_FS_CP_FIFO_PIPE({
@@ -230,6 +237,7 @@ async function getStatsForCopy(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
throw new ERR_FS_CP_UNKNOWN({
@@ -237,6 +245,7 @@ async function getStatsForCopy(destStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
@@ -255,6 +264,7 @@ async function mayCopyFile(srcStat, src, dest, opts) {
path: dest,
syscall: 'cp',
errno: EEXIST,
code: 'EEXIST',
});
}
}
@@ -355,6 +365,7 @@ async function onLink(destStat, src, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
// Do not copy if src is a subdir of dest since unlinking
@@ -367,6 +378,7 @@ async function onLink(destStat, src, dest) {
path: dest,
syscall: 'cp',
errno: EINVAL,
code: 'EINVAL',
});
}
return copyLink(resolvedSrc, dest);