Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fs: update rm/rmdir validation messages
The validation code for the rm/rmdir functions treated the
options as distinct parameters instead of the options properties
that they are. This commit updates the validation to treat them
like properties.
  • Loading branch information
cjihrig committed Oct 11, 2020
commit 6894c2fdc692c5ea3030a8c85187f325b5527b6d
10 changes: 5 additions & 5 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ const defaultRmdirOptions = {
const validateRmOptions = hideStackFrames((path, options, callback) => {
try {
options = validateRmdirOptions(options, defaultRmOptions);
validateBoolean(options.force, 'force');
validateBoolean(options.force, 'options.force');
} catch (err) {
return callback(err);
}
Expand Down Expand Up @@ -703,7 +703,7 @@ const validateRmOptions = hideStackFrames((path, options, callback) => {

const validateRmOptionsSync = hideStackFrames((path, options) => {
options = validateRmdirOptions(options, defaultRmOptions);
validateBoolean(options.force, 'force');
validateBoolean(options.force, 'options.force');

try {
const stats = lazyLoadFs().statSync(path);
Expand Down Expand Up @@ -737,9 +737,9 @@ const validateRmdirOptions = hideStackFrames(

options = { ...defaults, ...options };

validateBoolean(options.recursive, 'recursive');
validateInt32(options.retryDelay, 'retryDelay', 0);
validateUint32(options.maxRetries, 'maxRetries');
validateBoolean(options.recursive, 'options.recursive');
validateInt32(options.retryDelay, 'options.retryDelay', 0);
validateUint32(options.maxRetries, 'options.maxRetries');

return options;
});
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function removeAsync(dir) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "recursive" argument must be of type boolean\./
message: /^The "options\.recursive" property must be of type boolean\./
});
});

Expand All @@ -261,7 +261,7 @@ function removeAsync(dir) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "force" argument must be of type boolean\./
message: /^The "options\.force" property must be of type boolean\./
});
});

Expand All @@ -270,14 +270,14 @@ function removeAsync(dir) {
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "retryDelay" is out of range\./
message: /^The value of "options\.retryDelay" is out of range\./
});

assert.throws(() => {
validateRmOptionsSync(filePath, { maxRetries: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "maxRetries" is out of range\./
message: /^The value of "options\.maxRetries" is out of range\./
});
}
6 changes: 3 additions & 3 deletions test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function removeAsync(dir) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "recursive" argument must be of type boolean\./
message: /^The "options\.recursive" property must be of type boolean\./
});
});

Expand All @@ -200,14 +200,14 @@ function removeAsync(dir) {
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "retryDelay" is out of range\./
message: /^The value of "options\.retryDelay" is out of range\./
});

assert.throws(() => {
validateRmdirOptions({ maxRetries: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "maxRetries" is out of range\./
message: /^The value of "options\.maxRetries" is out of range\./
});
}