errors: improve ERR_INVALID_ARG_TYPE
The error message might be misleading if an object property was the issue and not the argument itself. Fix this by checking if a argument or a property is passed to the handler function. PR-URL: https://github.com/nodejs/node/pull/13730 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
parent
2a46e57d13
commit
3e178848a5
@ -192,7 +192,8 @@ E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' +
|
|||||||
function invalidArgType(name, expected, actual) {
|
function invalidArgType(name, expected, actual) {
|
||||||
const assert = lazyAssert();
|
const assert = lazyAssert();
|
||||||
assert(name, 'name is required');
|
assert(name, 'name is required');
|
||||||
var msg = `The "${name}" argument must be ${oneOf(expected, 'type')}`;
|
const type = name.includes('.') ? 'property' : 'argument';
|
||||||
|
var msg = `The "${name}" ${type} must be ${oneOf(expected, 'type')}`;
|
||||||
if (arguments.length >= 3) {
|
if (arguments.length >= 3) {
|
||||||
msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
|
msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,13 @@ for (let i = 0; i < 10; i++) {
|
|||||||
const invalidUserArgument = common.expectsError({
|
const invalidUserArgument = common.expectsError({
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "preValue.user" argument must be of type Number'
|
message: 'The "preValue.user" property must be of type Number'
|
||||||
});
|
});
|
||||||
|
|
||||||
const invalidSystemArgument = common.expectsError({
|
const invalidSystemArgument = common.expectsError({
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "preValue.system" argument must be of type Number'
|
message: 'The "preValue.system" property must be of type Number'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ assert.throws(function() {
|
|||||||
}, common.expectsError({
|
}, common.expectsError({
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "superCtor.prototype" argument must be of type function'
|
message: 'The "superCtor.prototype" property must be of type function'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user