FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

errors: refactor `invalidArgType()` by Trott · Pull Request #15544 · nodejs/node · GitHub

/ node Public

errors: refactor invalidArgType() - #15544

Closed
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:refactor-internal-errors
Closed

errors: refactor invalidArgType()#15544
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:refactor-internal-errors

Conversation

Trott commented Sep 21, 2017

Copy link
Copy Markdown
Member

invalidArgType() uses includes() in two places where startsWith()
and endsWith() are more appropriate (at least in my opinion). Switch
to those more specific functions.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

errors

`invalidArgType()` uses `includes()` in two places where `startsWith()`
and `endsWith()` are more appropriate (at least in my opinion). Switch
to those more specific functions.
Trott added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Sep 21, 2017
Comment thread lib/internal/errors.js
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')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Any reason not to check the type here too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

refack Sep 23, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm also -0 on over guarding an internal function.
IMHO if at all it should be at asserted around L309:

node/lib/internal/errors.js

Lines 307 to 309 in adbed02

function invalidArgType(name, expected, actual) {
internalAssert(name, 'name is required');

Comment thread lib/internal/errors.js
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')) {

refack Sep 23, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm also -0 on over guarding an internal function.
IMHO if at all it should be at asserted around L309:

node/lib/internal/errors.js

Lines 307 to 309 in adbed02

function invalidArgType(name, expected, actual) {
internalAssert(name, 'name is required');

Comment thread lib/internal/errors.js
// determiner: 'must be' or 'must not be'
let determiner;
if (expected.includes('not ')) {
if (typeof expected === 'string' && expected.startsWith('not ')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

Landed in cef6e1c

BridgeAR closed this Sep 24, 2017
BridgeAR pushed a commit that referenced this pull request Sep 24, 2017
`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 <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>

jasnell commented Sep 25, 2017

Copy link
Copy Markdown
Member

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.

addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 30, 2017
`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>
Trott deleted the refactor-internal-errors branch January 13, 2022 22:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

errors Issues and PRs related to JavaScript errors originated in Node.js core.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL