Skip to content

Commit

Permalink
path: fix incorrect use of ERR_INVALID_ARG_TYPE
Browse files Browse the repository at this point in the history
PR-URL: #14011
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
tniessen committed Jul 3, 2017
1 parent 1d74143 commit 44256bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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);
},
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,19 @@ function checkFormat(path, testCases) {
testCases.forEach(function(testCase) {
assert.strictEqual(path.format(testCase[0]), testCase[1]);
});

function typeName(value) {
return value === null ? 'null' : typeof value;
}

[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
assert.throws(() => {
path.format(pathObject);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. Received ' +
'type ' + typeName(pathObject)
}));
});
}

0 comments on commit 44256bb

Please sign in to comment.