GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: improve the usage of TypeError[INVALID_ARG_TYPE] by starkwang · Pull Request #16401 · nodejs/node

Conversation

@starkwang

@starkwang starkwang commented Oct 23, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The initials of expected in TypeError[ERR_INVALID_ARG_TYPE] are inconsistent.

This PR is to:

  • Unify the initial usage of TypeError[INVALID_ARG_TYPE]
  • Add an argument check before construct an error
  • Revise some inappropriate usage of INVALID_ARG_TYPE

Fixes: #16383

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

lib

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs involving general changes in the lib/ or src/ directories. label Oct 23, 2017
apapirovski
apapirovski reviewed Oct 23, 2017
View reviewed changes

@apapirovski apapirovski left a comment

Copy link
Copy Markdown
Contributor

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.

Some decisions probably need to be made re: functions and objects. Neither is technically a primitive.

Not sure how I feel about the need for checkExpectedTypeInitial — feels like reviewing PRs and modifying all existing usage would take care of its purpose.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/crypto/random.js Outdated

@apapirovski apapirovski Oct 23, 2017

Copy link
Copy Markdown
Contributor

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.

Tempted to say that uint32 being lowercase was correct... here and in all other instances that aren't referring to Uint32Array.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@starkwang

starkwang commented Oct 23, 2017

Copy link
Copy Markdown
Contributor Author

Some decisions probably need to be made re: functions and objects. Neither is technically a primitive.

@apapirovski Agreed. But most of the codes using function and object instead of uppercase initial. I'm also confused with the strange convention.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@starkwang
starkwang force-pushed the improve-invalid-arg-type branch from 393b85c to 670dab3 Compare October 23, 2017 16:29
@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 23, 2017
@jasnell

jasnell commented Oct 23, 2017

Copy link
Copy Markdown
Member

Defensively marking as semver-major... these type of changes should only need to be semver-major while we are still in the process of converting the errors over to the new mechanism.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lpinca

lpinca commented Oct 24, 2017

Copy link
Copy Markdown
Member

Not sure how I feel about the need for checkExpectedTypeInitial — feels like reviewing PRs and modifying all existing usage would take care of its purpose.

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 27, 2017

Copy link
Copy Markdown
Member

Defensively marking as semver-major... these type of changes should only need to be semver-major while we are still in the process of converting the errors over to the new mechanism.

@jasnell A lot of changes here only affect the error message. If this PR can split those changes touching error codes/adding additional throws out then IMO we could land the message-only changes as semver-patch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 27, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Some decisions probably need to be made re: functions and objects. Neither is technically a primitive.

@apapirovski I'd say...let's go with util.isPrimitive.

> util.isPrimitive(() => {})
false
> util.isPrimitive({})
false
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski

apapirovski commented Oct 27, 2017

Copy link
Copy Markdown
Contributor

@joyeecheung yeah, I agree — more about whether we capitalize or not. I feel like Function looks a bit weird but it's not a primitive so...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apapirovski
apapirovski reviewed Oct 27, 2017
View reviewed changes
Comment thread lib/internal/errors.js Outdated

@apapirovski apapirovski Oct 27, 2017

Copy link
Copy Markdown
Contributor

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.

If this remains in some form, it should be made into a lint rule. Otherwise it should IMO be removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
joyeecheung
joyeecheung reviewed Oct 27, 2017
View reviewed changes

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

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.

Can you split the message-only changes into separate commits? (I guess we need to split the PR as well) That way they don't have to be semver-major.

Personally I prefer not to check the capitalizations of types in runtime, we can probably just make another eslint rule for it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/errors.js Outdated

@joyeecheung joyeecheung Oct 27, 2017

Copy link
Copy Markdown
Member

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.

Since primitiveTypes is full of lowercase strings we can just do expectedType.toLowerCase()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/errors.js Outdated

@joyeecheung joyeecheung Oct 27, 2017

Copy link
Copy Markdown
Member

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.

primitiveTypes.includes(lowercase)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@starkwang

starkwang commented Oct 27, 2017

Copy link
Copy Markdown
Contributor Author

Can you split the message-only changes into separate commits? (I guess we need to split the PR as well) That way they don't have to be semver-major.

@joyeecheung Sorry I don't understand fully. Do you mean that split every file change (about error message) into separate commits? It will be a lot of commits I guess.

Personally I prefer not to check the capitalizations of types in runtime, we can probably just make another eslint rule for it.

Agreed. I will remove it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 28, 2017

Copy link
Copy Markdown
Member

@starkwang Sorry for not being clear enough. Some of the changes here do not add additional throw or change the error code (i.e. do not change the first argument like "ERR_*", basically they just change the capitalization, so only the errror messages are changed), those can be split into one commit, and do not have to be sermver-major(that is, can go into 8.x). Those that do change the code or add additional throws can be split into another commit and will have to wait until 9.x

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@starkwang
starkwang force-pushed the improve-invalid-arg-type branch from 670dab3 to c74148d Compare October 28, 2017 10:36
@starkwang

starkwang commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

@joyeecheung I've just reduced this PR into message-only changes, which unifies the initials.
I will create another PR to fix the inappropriate error codes (they were in this PR before).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 28, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

LGTM once this changes object -> Object and function -> Function, because we use the capitalized names in the documentation as well, IMO we should be more consistent on this.

Also I think I have incorrectly estimated the timeline in #16401 (comment) , from a quick glance I think none of the errors changed here can be backported in v8.x becuase they have not been migrated there in April anyway. The changes in this PR should be safe to land in v9.x and the other semver-major changes would probably need to wait for v10.x because we are very close to cut v9.x now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 28, 2017
@starkwang
starkwang force-pushed the improve-invalid-arg-type branch from c74148d to 75e6dd5 Compare October 28, 2017 15:32
@starkwang

starkwang commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

Pushed commit to address comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joyeecheung
joyeecheung approved these changes Oct 28, 2017
View reviewed changes

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

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.

LGTM with a odd finding. We should probably do an audit on the types passed to ERR_INVALID_ARG_TYPE later...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/fs.js Outdated

@joyeecheung joyeecheung Oct 28, 2017

Copy link
Copy Markdown
Member

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.

Not really need to be fixed in this PR, but this should be ['Date', 'string', 'number']

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@joyeecheung

joyeecheung commented Oct 28, 2017

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/11055/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tniessen

tniessen commented Oct 28, 2017

Copy link
Copy Markdown
Member

Personally, I usually use lowercase for things which typeof returns a correct value for, e.g. number, function and object, but I guess consistency with the documentation makes sense.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@starkwang
starkwang force-pushed the improve-invalid-arg-type branch from 75e6dd5 to 6638db6 Compare November 3, 2017 14:13
@starkwang

starkwang commented Nov 11, 2017

Copy link
Copy Markdown
Contributor Author

@jasnell @joyeecheung @tniessen Is there anyone can review or land this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Nov 11, 2017

Copy link
Copy Markdown
Member

This is a message-only change on the migrated errors now so we don't need TSC approvals...going to land this tomorrow if no one objects. cc @nodejs/collaborators

New CI: https://ci.nodejs.org/job/node-test-pull-request/11352/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung self-assigned this Nov 11, 2017
gireeshpunathil
gireeshpunathil approved these changes Nov 11, 2017
View reviewed changes
@gireeshpunathil

gireeshpunathil commented Nov 11, 2017

Copy link
Copy Markdown
Member

for me, the types with actual casing that a compiler can successfully parse is one thing, and the types that a consumer can easily relate to is another thing, and it makes sense to abstract the strict syntax in human readable messages. However, consistency draws the bottom line.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Nov 11, 2017
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
evanlucas pushed a commit that referenced this pull request Nov 13, 2017
@starkwang @evanlucas
lib: improve the usage of TypeError[INVALID_ARG_TYPE]
c179254
The initials of expected in TypeError[ERR_INVALID_ARG_TYPE]
are inconsistent. This change is to unify them.

PR-URL: #16401
Fixes: #16383
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@evanlucas evanlucas mentioned this pull request Nov 13, 2017
v9.2.0 proposal #16992
Merged
@MylesBorins

MylesBorins commented Nov 17, 2017

Copy link
Copy Markdown
Contributor

Should this be backported to v6.x-staging or v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

As this PR touches more than 50 files it may have been nice to get a backport lined up when this landed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins MylesBorins added lts-watch-v6.x labels Nov 17, 2017
@joyeecheung

joyeecheung commented Nov 17, 2017

Copy link
Copy Markdown
Member

@MylesBorins This PR cannot land in v6.x or v8.x because it changes errors that have not been migrated in either branches, see #16401 (comment) . This should be possible to be backported to v9.x though, if it actually needs a backport.

MylesBorins reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung added dont-land-on-v6.x and removed lts-watch-v6.x labels Nov 17, 2017
@joyeecheung

joyeecheung commented Nov 17, 2017

Copy link
Copy Markdown
Member

@MylesBorins Ah nevermind, I see that it's already released on v9.2.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@starkwang starkwang mentioned this pull request Dec 9, 2017
tools: add lowercase-name-for-primitive eslint rule #17568
Closed
3 tasks done
starkwang added a commit to starkwang/node that referenced this pull request Dec 9, 2017
@starkwang
tools: add lowercase-name-for-primitive eslint rule
ea94065
Primitives should use lowercase in error message.

refs: nodejs#16401
addaleax pushed a commit to addaleax/node that referenced this pull request Dec 13, 2017
@starkwang @addaleax
tools: add lowercase-name-for-primitive eslint rule
a2bdcba
Primitives should use lowercase in error message.

Refs: nodejs#16401
PR-URL: nodejs#17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@gibfahn gibfahn mentioned this pull request Dec 19, 2017
test: refactor concat string to template string #17252
Closed
1 of 2 tasks
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
3ad8cf1
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 22, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
dc480f8
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 22, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
0f002dd
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 11, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
de25741
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 12, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
f0c1855
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 13, 2018
@starkwang @MylesBorins
tools: add lowercase-name-for-primitive eslint rule
7821a4c
Primitives should use lowercase in error message.

Refs: #16401
PR-URL: #17568
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@jasnell jasnell jasnell approved these changes
@benjamingr benjamingr benjamingr approved these changes
@joyeecheung joyeecheung joyeecheung approved these changes
@gireeshpunathil gireeshpunathil gireeshpunathil approved these changes
+1 more reviewer
@apapirovski apapirovski apapirovski left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

lib / src Issues and PRs involving general changes in the lib/ or src/ directories.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

lib: inconsistent initial of expected in TypeError[ERR_INVALID_ARG_TYPE]

Uh oh!

There was an error while loading. Please reload this page.

12 participants

@starkwang @jasnell @lpinca @joyeecheung @apapirovski @tniessen @gireeshpunathil @TimothyGu @MylesBorins @mcollina @benjamingr @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.