Skip to content

Commit 3e17884

Browse files
BridgeARrefack
authored andcommitted
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: #13730 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 2a46e57 commit 3e17884

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/internal/errors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' +
192192
function invalidArgType(name, expected, actual) {
193193
const assert = lazyAssert();
194194
assert(name, 'name is required');
195-
var msg = `The "${name}" argument must be ${oneOf(expected, 'type')}`;
195+
const type = name.includes('.') ? 'property' : 'argument';
196+
var msg = `The "${name}" ${type} must be ${oneOf(expected, 'type')}`;
196197
if (arguments.length >= 3) {
197198
msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
198199
}

test/parallel/test-process-cpuUsage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ for (let i = 0; i < 10; i++) {
3434
const invalidUserArgument = common.expectsError({
3535
code: 'ERR_INVALID_ARG_TYPE',
3636
type: TypeError,
37-
message: 'The "preValue.user" argument must be of type Number'
37+
message: 'The "preValue.user" property must be of type Number'
3838
});
3939

4040
const invalidSystemArgument = common.expectsError({
4141
code: 'ERR_INVALID_ARG_TYPE',
4242
type: TypeError,
43-
message: 'The "preValue.system" argument must be of type Number'
43+
message: 'The "preValue.system" property must be of type Number'
4444
});
4545

4646

test/parallel/test-util-inherits.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ assert.throws(function() {
8585
}, common.expectsError({
8686
code: 'ERR_INVALID_ARG_TYPE',
8787
type: TypeError,
88-
message: 'The "superCtor.prototype" argument must be of type function'
88+
message: 'The "superCtor.prototype" property must be of type function'
8989
})
9090
);
9191
assert.throws(function() {

0 commit comments

Comments
 (0)