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 — errors: improve invalid arg type by BridgeAR · Pull Request #13834 · nodejs/node

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Jun 21, 2017

Copy link
Copy Markdown
Member

I reworked the ERR_INVALID_ARG_TYPE error type in a way that provides more information to the user than before.
All of these errors now return what was actually provided and failed.
The information about what was provided and what is expected is more specific (as in not only the type is checked but also the constructor).
I also fixed a few typos and wrong usages like using typeof arg as actual value instead of arg and one entry that actually checks a property, not an argument.

There is one point that might be thought about: mixing multiple expected values can only print either instance of or type of. So ['Array', 'string'] will result in instance of Array or string and not instance of Array or type of string. I could test each entry but I feel that is somewhat unnecessary?

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)

errors

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 dont-land-on-v4.x errors Issues and PRs related to JavaScript errors originating in Node.js core. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Jun 21, 2017
@BridgeAR BridgeAR changed the title Improve invalid arg type errors: improve invalid arg type Jun 21, 2017
@BridgeAR

BridgeAR commented Jun 21, 2017

Copy link
Copy Markdown
Member Author

Ref #13730
Ref #13733 (one error is actually not touched here and is fixed in this PR instead).

All reactions

Sorry, something went wrong.

Uh oh!

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

mscdex
mscdex reviewed Jun 21, 2017
View reviewed changes
Comment thread lib/internal/errors.js Outdated

@mscdex mscdex Jun 21, 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.

You may want to use single equals to also check for null.

Sorry, something went wrong.

Uh oh!

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

All reactions

@BridgeAR BridgeAR Jun 21, 2017

Copy link
Copy Markdown
Member Author

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.

Hm, as far as I can tell someone would have to explicitly set the constructor to null... that would be really weird but I'll change it accordingly.

Sorry, something went wrong.

Uh oh!

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

All reactions
@mscdex mscdex added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 21, 2017
@mscdex

mscdex commented Jun 21, 2017

Copy link
Copy Markdown
Contributor

Marking as semver-major due to changes in error messages.

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR

BridgeAR commented Jun 21, 2017

Copy link
Copy Markdown
Member Author

@mscdex this should not be semver major as the main intention of the internal errors was to change error messages when ever.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mscdex

mscdex commented Jun 21, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@BridgeAR Right, that's the end goal, but I think until the new error mechanism is widely adopted (e.g. users start checking the special error properties instead of .message) we're still marking error message changes as semver-major. /cc @jasnell to be sure.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mhdawson

mhdawson commented Jun 23, 2017

Copy link
Copy Markdown
Member

Like the improvement. Agree we should still be making these changes semver-major until we get overall agreement that we can starting treating error messages changes differently.

Also needs a rebase.

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack

refack commented Jun 23, 2017

Copy link
Copy Markdown
Contributor

Like the improvement. Agree we should still be making these changes semver-major until we get overall agreement that we can starting treating error messages changes differently.

There are mixed messages being conveyed #13730 (comment)... IMHO the CTC should discuss and decide.
ping @jasnell

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack refack mentioned this pull request Jun 25, 2017
Node.js Foundation Core Technical Committee (CTC) Meeting 2017-06-28 nodejs/CTC#148
Closed
@BridgeAR
BridgeAR force-pushed the improve-invalid-arg-type branch from c180fec to 63c5700 Compare June 26, 2017 12:11
@BridgeAR

BridgeAR commented Jun 26, 2017

Copy link
Copy Markdown
Member Author

Rebased

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack

refack commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

IMHO in the tests when you assert the message it should be a RegEx anchored with start-of-line and end in "Received": /^The "last argument" argument must be of type function\. Received/ because whatever comes after "Received" is dependent of the actual input, while the rest is static for each case.

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack

refack commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

Another idea: export a function from errors: invalidArg(opts) that you use as error.invalidArgs({expected: "gaga", bar}); then you can infer the type of the second arg's name and value:

function invalidArg(opts) {
  assert.strictEqual(Object.keys(opts).length, 2);
  assert.strictEqual('expected' in opts, true);
  const exp = opts.expected;
  delete opts.expected;
  const actKey = Object.keys(opts)[0];
  const actVal = opts[actKey];
  throw new TypeError('ERR_INVALID_ARG_TYPE', actKey, exp, actVal
// if we add a stackLimit arg
// ,invalidArg);
}
All reactions

Sorry, something went wrong.

Uh oh!

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

refack
refack reviewed Jun 26, 2017
View reviewed changes

@refack refack 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.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread test/parallel/test-process-cpuUsage.js Outdated

@refack refack Jun 26, 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.

Could you anchor these /^...

Sorry, something went wrong.

Uh oh!

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

All reactions

@BridgeAR BridgeAR Jun 26, 2017

Copy link
Copy Markdown
Member Author

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.

Addressed

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread lib/util.js Outdated

@refack refack Jun 26, 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.

IMHO for readability use undefined

Sorry, something went wrong.

Uh oh!

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

All reactions

@BridgeAR BridgeAR Jun 26, 2017

Copy link
Copy Markdown
Member Author

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 personally prefer it this way to have a consistent way of doing this but I don't have strong feelings about it.

Sorry, something went wrong.

Uh oh!

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

All reactions

@refack refack Jun 26, 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.

👍 Generally I yield to the OP. So it's your call.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread lib/util.js Outdated

@refack refack Jun 26, 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.

Personal style nit: Is these cases chop down the args like in L1082

Sorry, something went wrong.

Uh oh!

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

All reactions

@BridgeAR BridgeAR Jun 26, 2017

Copy link
Copy Markdown
Member Author

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.

Addressed

Sorry, something went wrong.

Uh oh!

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

All reactions
@refack refack mentioned this pull request Jun 26, 2017
meta: semver impact of Error messages #13937
Closed
@BridgeAR
BridgeAR force-pushed the improve-invalid-arg-type branch from 63c5700 to 0d4204c Compare June 26, 2017 20:51
@BridgeAR

BridgeAR commented Jun 26, 2017

Copy link
Copy Markdown
Member Author

@refack

you can infer the type of the second arg's name and value

I feel like this is a bit to much magic and the call itself won't be much shorter. So I'd say let's stick to how it is currently.


I also added the Received part in the RegExp if the line length allowed it. I hope that's fine, I personally don't see much benefit in adding the Received as it might theoretically change and it is already checked that all arguments are properly passed to the internal error.

All reactions

Sorry, something went wrong.

Uh oh!

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

@refack

refack commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

you can infer the type of the second arg's name and value

I feel like this is a bit to much magic and the call itself won't be much shorter. So I'd say let's stick to how it is currently.

👍

I also added the Received part in the RegExp if the line length allowed it. I hope that's fine, I personally don't see much benefit in adding the Received as it might theoretically change and it is already checked that all arguments are properly passed to the internal error.

Just so it doesn't change "accidentally". Changes in test files get more review attention, so IMHO it's best to assert as much as possible, then later change carefully.

All reactions

Sorry, something went wrong.

Uh oh!

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

refack
refack approved these changes Jun 26, 2017
View reviewed changes
@refack

refack commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

Sanity: https://ci.nodejs.org/job/node-test-commit-linuxone/6883/

All reactions

Sorry, something went wrong.

Uh oh!

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

@BridgeAR
BridgeAR force-pushed the improve-invalid-arg-type branch from 0d4204c to dc4e540 Compare June 29, 2017 11:27
@BridgeAR

BridgeAR commented Jun 29, 2017

Copy link
Copy Markdown
Member Author

Rebased

All reactions

Sorry, something went wrong.

Uh oh!

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

mhdawson
mhdawson approved these changes Jun 29, 2017
View reviewed changes

@mhdawson mhdawson 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 question. In a number of tests the check stops at 'Received' any reason we can't validate the additional information after 'Received' as well ?

Sorry, something went wrong.

Uh oh!

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

All reactions
@BridgeAR

BridgeAR commented Jun 29, 2017

Copy link
Copy Markdown
Member Author

It is in most cases possible to use the exact value. In the end I don't think that it's that important to test for the message strictly as it can change more often but I'm fine with changing it.

All reactions

Sorry, something went wrong.

Uh oh!

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

This was referenced Sep 15, 2021
[Snyk] Fix for 1 vulnerabilities Zintexiss/node-22#60
Open
[Snyk] Fix for 1 vulnerabilities baby636/node#22
Open
[Snyk] Fix for 1 vulnerabilities Dmarch28/node#37
Open
[Snyk] Fix for 1 vulnerabilities baby636/node#23
Open
[Snyk] Security upgrade eslint from 6.8.0 to 7.16.0 baby636/node#24
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 Zintexiss/node-22#62
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 Zintexiss/node-22#63
Open
[Snyk] Fix for 1 vulnerabilities ron-a20/node#45
Open
[Snyk] Fix for 1 vulnerabilities Rednickle/node-1#32
Open
[Snyk] Fix for 1 vulnerabilities meghasfdc/node#46
Open
[Snyk] Fix for 1 vulnerabilities aliceUnhinged613/node#36
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 baby636/node#25
Open
[Snyk] Fix for 1 vulnerabilities Zintexiss/node-22#64
Open
[Snyk] Fix for 1 vulnerabilities baby636/node#26
Open
[Snyk] Fix for 1 vulnerabilities ryan-ally/node#41
Open
[Snyk] Fix for 1 vulnerabilities 137717unity/node#38
Open
[Snyk] Fix for 1 vulnerabilities wedataintelligence/node#14
Open
[Snyk] Fix for 1 vulnerabilities kissofire/node#47
Open
[Snyk] Fix for 1 vulnerabilities ryan-ally/node#42
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 Zintexiss/node-22#65
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 ryan-ally/node#43
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 ryan-ally/node#44
Open
[Snyk] Fix for 1 vulnerabilities sitedata/node#37
Open
[Snyk] Security upgrade eslint from 6.8.0 to 7.16.0 ryan-ally/node#45
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 ryan-ally/node#46
Open
[Snyk] Security upgrade eslint from 6.8.0 to 7.16.0 Mement-Mori/node#12
Open
[Snyk] Security upgrade eslint from 6.8.0 to 7.16.0 MaxMood96/node#13
Open
[Snyk] Security upgrade eslint from 5.16.0 to 7.16.0 baby636/node#27
Open
[Snyk] Fix for 1 vulnerabilities molllyn1/node#27
Open
@snyk-bot snyk-bot mentioned this pull request Feb 12, 2022
[Snyk] Fix for 9 vulnerabilities Iceymann18777/node#10
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@joyeecheung joyeecheung joyeecheung approved these changes
+3 more reviewers
@mscdex mscdex mscdex left review comments
@refack refack refack approved these changes
@mhdawson mhdawson mhdawson approved these changes
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

blocked PRs that are blocked by other issues or PRs. errors Issues and PRs related to JavaScript errors originating in Node.js core. invalid Issues and PRs that are invalid. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. semver-major PRs that contain breaking changes and should be released in the next major version. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

8 participants

@BridgeAR @mscdex @mhdawson @refack @gibfahn @joyeecheung @Trott @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 01402775 — 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.