Skip to content

Commit 28e4e43

Browse files
committed
errors: make input mandatory
Using ERR_INVALID_ARG_TYPE will now require the received value as well. This makes sure the errors are always expressive. It also drops support for using an array as name argument. PR-URL: #19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent b38c81c commit 28e4e43

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/internal/errors.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ function sysError(code, syscall, path, dest,
936936
messages.set('ERR_SYSTEM_ERROR', sysError);
937937

938938
function invalidArgType(name, expected, actual) {
939-
internalAssert(name, 'name is required');
939+
internalAssert(typeof name === 'string');
940+
internalAssert(arguments.length === 3);
940941

941942
// determiner: 'must be' or 'must not be'
942943
let determiner;
@@ -948,21 +949,16 @@ function invalidArgType(name, expected, actual) {
948949
}
949950

950951
let msg;
951-
if (Array.isArray(name)) {
952-
var names = name.map((val) => `"${val}"`).join(', ');
953-
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
954-
} else if (name.endsWith(' argument')) {
955-
// for the case like 'first argument'
952+
if (name.endsWith(' argument')) {
953+
// For cases like 'first argument'
956954
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
957955
} else {
958956
const type = name.includes('.') ? 'property' : 'argument';
959957
msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`;
960958
}
961959

962-
// If actual value received, output it
963960
// TODO(BridgeAR): Improve the output by showing `null` and similar.
964-
if (arguments.length === 3)
965-
msg += `. Received type ${typeof actual}`;
961+
msg += `. Received type ${typeof actual}`;
966962
return msg;
967963
}
968964

0 commit comments

Comments
 (0)