Skip to content

Commit cef6e1c

Browse files
TrottBridgeAR
authored andcommitted
errors: refactor invalidArgType()
`invalidArgType()` uses `includes()` in two places where `startsWith()` and `endsWith()` are more appropriate (at least in my opinion). Switch to those more specific functions. PR-URL: #15544 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 33760cc commit cef6e1c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/internal/errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function invalidArgType(name, expected, actual) {
309309

310310
// determiner: 'must be' or 'must not be'
311311
let determiner;
312-
if (expected.includes('not ')) {
312+
if (typeof expected === 'string' && expected.startsWith('not ')) {
313313
determiner = 'must not be';
314314
expected = expected.split('not ')[1];
315315
} else {
@@ -320,7 +320,7 @@ function invalidArgType(name, expected, actual) {
320320
if (Array.isArray(name)) {
321321
var names = name.map((val) => `"${val}"`).join(', ');
322322
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
323-
} else if (name.includes(' argument')) {
323+
} else if (name.endsWith(' argument')) {
324324
// for the case like 'first argument'
325325
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
326326
} else {

0 commit comments

Comments
 (0)