Skip to content

Commit

Permalink
fs: update rm/rmdir validation messages
Browse files Browse the repository at this point in the history
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.

PR-URL: #35565
Reviewed-By: Ben Coe <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Masashi Hirano <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Oct 14, 2020
1 parent 937fa5d commit 3a401b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
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\./
});
}

0 comments on commit 3a401b8

Please sign in to comment.