From 3a401b86958a36b695a05f921484a0fe6d15448f Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 11 Oct 2020 11:06:43 -0400 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/35565 Reviewed-By: Ben Coe Reviewed-By: Luigi Pinca Reviewed-By: Denys Otrishko Reviewed-By: Rich Trott Reviewed-By: Masashi Hirano --- lib/internal/fs/utils.js | 10 +++++----- test/parallel/test-fs-rm.js | 8 ++++---- test/parallel/test-fs-rmdir-recursive.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index da307f59f7a8fe..300d8bf9b956da 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -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); } @@ -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); @@ -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; }); diff --git a/test/parallel/test-fs-rm.js b/test/parallel/test-fs-rm.js index 47567c6e65b75f..5db6c7f6447ef6 100644 --- a/test/parallel/test-fs-rm.js +++ b/test/parallel/test-fs-rm.js @@ -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\./ }); }); @@ -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\./ }); }); @@ -270,7 +270,7 @@ 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(() => { @@ -278,6 +278,6 @@ function removeAsync(dir) { }, { 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\./ }); } diff --git a/test/parallel/test-fs-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js index db8d4b14dac7cf..95607333d5540c 100644 --- a/test/parallel/test-fs-rmdir-recursive.js +++ b/test/parallel/test-fs-rmdir-recursive.js @@ -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\./ }); }); @@ -200,7 +200,7 @@ 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(() => { @@ -208,6 +208,6 @@ function removeAsync(dir) { }, { 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\./ }); }