-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors: refactor invalidArgType()
#15544
Conversation
`invalidArgType()` uses `includes()` in two places where `startsWith()` and `endsWith()` are more appropriate (at least in my opinion). Switch to those more specific functions.
@@ -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')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to check the type here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's checked in the if
part. I mean, I guess it could be something other than a string or an array, but it's an internal function, so I'm not worried about end users sending an object or something.
My preference here is slight, though, and I can see the point of programming extra defensively here and adding the type check. If I do that, I'll want to add a test too to cover it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also -0 on over guarding an internal function.
IMHO if at all it should be at asserted around L309:
Lines 307 to 309 in adbed02
function invalidArgType(name, expected, actual) { | |
internalAssert(name, 'name is required'); | |
@@ -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')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also -0 on over guarding an internal function.
IMHO if at all it should be at asserted around L309:
Lines 307 to 309 in adbed02
function invalidArgType(name, expected, actual) { | |
internalAssert(name, 'name is required'); | |
@@ -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 ')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should always be a string. A failure would be totally fine out of my perspective as we should have tests for this anyway.
But I think it is not really important for now.
Landed in cef6e1c |
`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]>
This does not land cleanly in v8.x. I believe it depends on a previously landed semver-major but not entirely sure. Would need a backport if it's relevant. |
`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 <[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]>
invalidArgType()
usesincludes()
in two places wherestartsWith()
and
endsWith()
are more appropriate (at least in my opinion). Switchto those more specific functions.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
errors