Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect use of ERR_INVALID_ARG_TYPE #14011

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function _throws(shouldThrow, block, expected, message) {
if (typeof block !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
typeof block);
block);
}

if (typeof expected === 'string') {
Expand Down
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
14 changes: 9 additions & 5 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,9 @@ try {

{
// Verify that throws() and doesNotThrow() throw on non-function block
const validationFunction = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
function typeName(value) {
return value === null ? 'null' : typeof value;
}

const testBlockTypeError = (method, block) => {
let threw = true;
Expand All @@ -681,7 +680,12 @@ try {
method(block);
threw = false;
} catch (e) {
validationFunction(e);
common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "block" argument must be of type function. Received ' +
'type ' + typeName(block)
})(e);
}

assert.ok(threw);
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)
}));
});
}