diff --git a/lib/path.js b/lib/path.js index f8d0e822bf1d9b..f7d02b992f626d 100644 --- a/lib/path.js +++ b/lib/path.js @@ -960,7 +960,7 @@ const win32 = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', - typeof pathObject); + pathObject); } return _format('\\', pathObject); }, @@ -1503,7 +1503,7 @@ const posix = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', - typeof pathObject); + pathObject); } return _format('/', pathObject); }, diff --git a/test/parallel/test-path-format-error.js b/test/parallel/test-path-format-error.js new file mode 100644 index 00000000000000..32a2a079b77600 --- /dev/null +++ b/test/parallel/test-path-format-error.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const path = require('path'); +const assert = require('assert'); + +const invalidInput = [ + 111, + 'foo', + undefined, + () => {} +]; +invalidInput.forEach((val) => { + const err = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "pathObject" argument must be of type Object. ' + + `Received type ${typeof val}` + }); + assert.throws(function() { + path.format(val); + }, err); +});