-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 { | ||||||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. It's checked in the 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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm also -0 on over guarding an internal function. Lines 307 to 309 in adbed02
|
||||||||
// for the case like 'first argument' | ||||||||
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`; | ||||||||
} else { | ||||||||
|
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.