diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 5ff7a281651f7b..da307f59f7a8fe 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -37,6 +37,7 @@ const { const { once } = require('internal/util'); const { toPathIfFileURL } = require('internal/url'); const { + validateBoolean, validateInt32, validateUint32 } = require('internal/validators'); @@ -674,15 +675,11 @@ const defaultRmdirOptions = { const validateRmOptions = hideStackFrames((path, options, callback) => { try { options = validateRmdirOptions(options, defaultRmOptions); + validateBoolean(options.force, 'force'); } catch (err) { return callback(err); } - if (typeof options.force !== 'boolean') - return callback( - new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force) - ); - lazyLoadFs().stat(path, (err, stats) => { if (err) { if (options.force && err.code === 'ENOENT') { @@ -706,9 +703,7 @@ const validateRmOptions = hideStackFrames((path, options, callback) => { const validateRmOptionsSync = hideStackFrames((path, options) => { options = validateRmdirOptions(options, defaultRmOptions); - - if (typeof options.force !== 'boolean') - throw new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force); + validateBoolean(options.force, 'force'); try { const stats = lazyLoadFs().statSync(path); @@ -742,9 +737,7 @@ const validateRmdirOptions = hideStackFrames( options = { ...defaults, ...options }; - if (typeof options.recursive !== 'boolean') - throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', options.recursive); - + validateBoolean(options.recursive, 'recursive'); validateInt32(options.retryDelay, 'retryDelay', 0); validateUint32(options.maxRetries, 'maxRetries');