Skip to content

Commit

Permalink
errors: refactor invalidArgType()
Browse files Browse the repository at this point in the history
`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: nodejs/node#15544
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Trott authored and addaleax committed Sep 30, 2017
1 parent ebe8c88 commit 2c35a60
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function invalidArgType(name, expected, actual) {

// determiner: 'must be' or 'must not be'
let determiner;
if (expected.includes('not ')) {
if (typeof expected === 'string' && expected.startsWith('not ')) {
determiner = 'must not be';
expected = expected.split('not ')[1];
} else {
Expand All @@ -320,7 +320,7 @@ function invalidArgType(name, expected, actual) {
if (Array.isArray(name)) {
var names = name.map((val) => `"${val}"`).join(', ');
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
} else if (name.includes(' argument')) {
} else if (name.endsWith(' argument')) {
// for the case like 'first argument'
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
} else {
Expand Down

0 comments on commit 2c35a60

Please sign in to comment.