diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index a3ef20b708a030..5b57de3f7dda03 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -10,7 +10,6 @@ const { FunctionPrototypeCall, Number, NumberIsFinite, - NumberIsInteger, MathMin, MathRound, ObjectIs, @@ -862,14 +861,8 @@ const getValidMode = hideStackFrames((mode, type) => { if (mode == null) { return def; } - if (NumberIsInteger(mode) && mode >= min && mode <= max) { - return mode; - } - if (typeof mode !== 'number') { - throw new ERR_INVALID_ARG_TYPE('mode', 'integer', mode); - } - throw new ERR_OUT_OF_RANGE( - 'mode', `an integer >= ${min} && <= ${max}`, mode); + validateInteger(mode, 'mode', min, max); + return mode; }); const validateStringAfterArrayBufferView = hideStackFrames((buffer, name) => { diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 744d23b4e95080..66089049e0cf07 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -170,14 +170,12 @@ fs.accessSync(readWriteFile, mode); () => fs.access(readWriteFile, mode, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - message: /"mode" argument.+integer/ } ); assert.throws( () => fs.accessSync(readWriteFile, mode), { code: 'ERR_INVALID_ARG_TYPE', - message: /"mode" argument.+integer/ } ); }); @@ -194,14 +192,12 @@ fs.accessSync(readWriteFile, mode); () => fs.access(readWriteFile, mode, common.mustNotCall()), { code: 'ERR_OUT_OF_RANGE', - message: /"mode".+It must be an integer >= 0 && <= 7/ } ); assert.throws( () => fs.accessSync(readWriteFile, mode), { code: 'ERR_OUT_OF_RANGE', - message: /"mode".+It must be an integer >= 0 && <= 7/ } ); }); diff --git a/test/parallel/test-fs-copyfile.js b/test/parallel/test-fs-copyfile.js index 1bfa410a124d2d..cbe79adf02c478 100644 --- a/test/parallel/test-fs-copyfile.js +++ b/test/parallel/test-fs-copyfile.js @@ -156,8 +156,6 @@ assert.throws(() => { }, { code: 'ERR_OUT_OF_RANGE', name: 'RangeError', - message: 'The value of "mode" is out of range. It must be an integer ' + - '>= 0 && <= 7. Received 8' }); assert.throws(() => { diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index e47dee023c9623..43185725e5fbcd 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -662,8 +662,7 @@ if (!common.isAIX) { // Check copyFile with invalid modes. { const validateError = { - message: /"mode".+must be an integer >= 0 && <= 7\. Received -1/, - code: 'ERR_OUT_OF_RANGE' + code: 'ERR_OUT_OF_RANGE', }; assert.throws( diff --git a/test/parallel/test-fs-promises-file-handle-sync.js b/test/parallel/test-fs-promises-file-handle-sync.js index 53eb2424549f93..07cfe98e99a5fd 100644 --- a/test/parallel/test-fs-promises-file-handle-sync.js +++ b/test/parallel/test-fs-promises-file-handle-sync.js @@ -14,7 +14,6 @@ async function validate() { copyFile(fixtures.path('baz.js'), dest, 'r'), { code: 'ERR_INVALID_ARG_TYPE', - message: /mode.*integer.*string/ } ); await copyFile(fixtures.path('baz.js'), dest); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index c0cfb468a2aed9..98f333421911e5 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -64,7 +64,6 @@ assert.strictEqual( access(__filename, 8), { code: 'ERR_OUT_OF_RANGE', - message: /"mode".*must be an integer >= 0 && <= 7\. Received 8$/ } ); @@ -72,7 +71,6 @@ assert.strictEqual( access(__filename, { [Symbol.toPrimitive]() { return 5; } }), { code: 'ERR_INVALID_ARG_TYPE', - message: /"mode" argument.+integer\. Received an instance of Object$/ } ); }