Skip to content
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

internal/errors: improve invalid arg type #14057

Closed
wants to merge 4 commits into from

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Jul 3, 2017

Something went wrong with #13834
This is the original change as it should be.

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

internal/errors

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jul 3, 2017
@refack
Copy link
Contributor

refack commented Jul 3, 2017

/cc @mscdex @joyeecheung @mhdawson, this is a fresh clone of #13834 PTAL

@refack refack added dont-land-on-v4.x errors Issues and PRs related to JavaScript errors originated in Node.js core. 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. labels Jul 3, 2017
@refack refack self-assigned this Jul 3, 2017
received = String(actual);
} else if (typeof actual === 'object') {
if (actual.constructor != null) {
received = `instance of ${actual.constructor.name}`;
Copy link

Choose a reason for hiding this comment

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

Provided that actual is an arbitrary user-provided object which we are validating, after this patch, exceptions can be raised on any of:

  • actual.constructor access.
  • actual.constructor.name access.
  • String concatenation with actual.constructor.name (if it's a Symbol or String(actual.constructor.name) throws)

Copy link

Choose a reason for hiding this comment

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

This is an uncommon code path, so wrapping in try-catch should be fine?

Copy link
Member Author

@BridgeAR BridgeAR Jul 3, 2017

Choose a reason for hiding this comment

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

I do not agree that it's useful to guard against a constructor or name property set to a getter that throws or being set to a symbol.
If this would ever result in an error, nothing bad would happen besides showing the "wrong" error.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

For the error type ERR_INVALID_ARG_TYPE the expected type
should be lower cased in case it's a primitive value.

The actual value should always be present as it increases the
provided error message information and it should not be passed
to the error type as is.

In addition this fixes some typos in the arguments names.
The error type ERR_INVALID_ARG_TYPE receives a actual value.
Make that mandatory so the error message has more detailed
information of what went wrong.
@BridgeAR
Copy link
Member Author

Rebased due to conflicts (the commits will have to be squashed as it would be really tedious to make each commit pass).

@refack
Copy link
Contributor

refack commented Jul 12, 2017

@mhdawson
Copy link
Member

Unfortunately this now needs a rebase again. Thanks for your patience.

@BridgeAR BridgeAR added blocked PRs that are blocked by other issues or PRs. and removed dont-land-on-v4.x whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Sep 23, 2017
@BridgeAR
Copy link
Member Author

Just as a note - I still plan on adding this but I decided to wait until all errors got ported. The reason was that it became really difficult to get this landed at that point of time due to lots of conflicting PRs.

As we are almost through with the error codes, I am going to look into this soon again.

@joyeecheung
Copy link
Member

@BridgeAR I think we are at a point where this PR can be revisited since most of the errors have now been ported

@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 7, 2018

@joyeecheung I would like to work on this again but I am not sure when I really get back to it. It is quite some significant work to refactor all those tests.

Because of that reason I am closing the PR for now. I might get back to it again at another point. I definitely want to work more on improving our errors in general.

@BridgeAR BridgeAR closed this Feb 7, 2018
@BridgeAR BridgeAR deleted the improve-invalid-arg-type branch April 1, 2019 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. errors Issues and PRs related to JavaScript errors originated in Node.js core. lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants