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

errors: add useOriginalName to internal/errors #22556

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.

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

@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Aug 27, 2018
@joyeecheung
Copy link
Member Author

Also for context on why we use our internal error system for the URL errors: #11299

@joyeecheung
Copy link
Member Author

joyeecheung commented Aug 27, 2018

There was also a discussion about restoring the behavior of error.name (couldn't find the link...cc @BridgeAR ?) I think we decided to keep them as-is. I haven't dug into the spec to see if we have to leave error.name alone, but I am guessing this is unspecified, so this patch is just a hack for the WPT harness.

@joyeecheung
Copy link
Member Author

joyeecheung commented Aug 27, 2018

or...maybe we have to leave the error names alone, at least for errors thrown from Web APIs :/

Refs: https://heycam.github.io/webidl/#dfn-exception-error-name

For simple exceptions, the error name is the type of the exception.

@jasnell
Copy link
Member

jasnell commented Aug 27, 2018

Not really a fan of this and really prefer to leave the internal/error names as they are currently. However, if this is just for testing, then definitely won't block

@joyeecheung
Copy link
Member Author

joyeecheung commented Aug 27, 2018

Not really a fan of this and really prefer to leave the internal/error names as they are currently. However, if this is just for testing, then definitely won't block

@jasnell Yeah this is just a hack for testing with the WPT harness directly instead of using our mocks. I am not entirely sure if it's technically a bug in our implementation (which means we need to fix it for users), or just a quirk that we need to deal with if we want to use the WPT harness in our own tests though, but it doesn't harm to have a workaround before we figure that out

// These are exported only to facilitate testing.
E,
get useOriginalName() { return useOriginalName; },
set useOriginalName(value) { useOriginalName = value; }
};
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding the useOriginalName couldn't you create a new error helper for more Web Platform related errors separate from the makeNodeErrorWithCode one?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jdalton I would if we decide to leave the names alone for those errors...but doesn't seem to worth it if it's just to work around the WPT harness and it's only for testing

Copy link
Member

@jdalton jdalton Aug 28, 2018

Choose a reason for hiding this comment

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

@joyeecheung Is it just a test harness thing are is the WPT fail hinting that URL errors should not have custom name's other than those of the builtin errors? If it means URL is not spec compliant then it's an issue for Node. If it is unspec'd then a bug should be filed for WPT.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #11299 If you feel strongly about this feel free to reopen that issue or open a new one. If we were to fix that, it has to be semver-major. This PR is just a work around so that we can update the tests without a semver-major change - I would rather not label a bunch of upcoming test update with semver-major and make them a backport burden.

Copy link
Member

@jdalton jdalton left a comment

Choose a reason for hiding this comment

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

Changing user accessible error APIs is not the answer here.

@joyeecheung
Copy link
Member Author

joyeecheung commented Aug 28, 2018

Changing user accessible error APIs is not the answer here.

@jdalton Can you elaborate on your reasoning behind this? We have been exposing user-accessible APIs - albeit internals that are behind flags - to facilitate testing, like the errors.E that have already existed for quite some time, which is exported together with errors.useOriginalName. It seems out of scope to debate whether we should make internal testing utilities (behind flags) accessible to users here.

@jdalton
Copy link
Member

jdalton commented Aug 28, 2018

This is a test harness concern and not worth moving into exposed APIs. I've given you a path forward that doesn't involving touching Node error APIs. Depending on where the fault is you can file a bug on WPT or work with Node to correct its errors. If it requires a major bump for Node then so be it. The WPT tests can be held until then.

@BridgeAR
Copy link
Member

BridgeAR commented Aug 28, 2018

@joyeecheung the issue is #20253.

I only found a single way to consistently adding the error code to the stack trace while keeping the name as is: directly after creating the error (or on creation) the name is set to err.name + ' [ERROR_CODE]', then the stack is accessed, the error name is reset to the original name and the error is returned... this however is a significant performance issue in case the error stack would not be accessed (but accessing the stack is normal when receiving an error, so that should be rare) and the prepareStackTrace function could not be used on received errors (this is something the user can not always expect though as the stack might already have been accessed somewhere in-between).

Other than that, the current implementation is AFAIK the only one possible.

Copy link
Member

@devsnek devsnek left a comment

Choose a reason for hiding this comment

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

this looks a-okay to me :shipit:

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Since this is internal, I am fine with it for now. We can still revise the solution if we find something better.

So LGTM.

@joyeecheung
Copy link
Member Author

joyeecheung commented Aug 28, 2018

This is a test harness concern and not worth moving into exposed APIs.

I would agree if this is a public API, but it is an internal API that is only accessible with the --expose-internals flag. As unfortunate as it is, altering internal APIs for test harness concerns is an established practice - searching for // Flags: --expose-internals under test yields 118 results on master.

EDIT: it appears I was on a outdated branch...the current number of Flags: --expose-internals under test is 156

Copy link
Member

@jdalton jdalton left a comment

Choose a reason for hiding this comment

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

Oh I see. I misunderstood where the useOriginalName getter/setters lived.

@refack
Copy link
Contributor

refack commented Aug 29, 2018

As unfortunate as it is, altering internal APIs for test harness concerns is an established practice - searching for // Flags: --expose-internals under test yields 118 results on master.

IMHO that's A Ok. At least for unit testing. Being able to "mock out" parts of the system is very important for predictable testing.

@refack
Copy link
Contributor

refack commented Aug 29, 2018

P.S. I know I'm late to tha party, but what is the purpose of this change?
NM found it This allows us to tell the type of the errors without using instanceof, which is necessary in WPT harness.

@@ -437,7 +442,10 @@ module.exports = {
getMessage,
SystemError,
codes,
E // This is exported only to facilitate testing.
// These are exported only to facilitate testing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add this This allows us to tell the type of the errors without using instanceof, which is necessary in WPT harness. to the comment.

@BridgeAR
Copy link
Member

BridgeAR commented Sep 5, 2018

Ping @joyeecheung

This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.
@joyeecheung
Copy link
Member Author

Addressed @refack 's comments.

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

@joyeecheung
Copy link
Member Author

I am going to land this tomorrow if there are no more comments etc.

@refack
Copy link
Contributor

refack commented Sep 16, 2018

Addressed @refack 's comments.

Thank you for following up.

@joyeecheung
Copy link
Member Author

Landed in e692a09, thanks!

joyeecheung added a commit that referenced this pull request Sep 17, 2018
This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.

PR-URL: #22556
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
targos pushed a commit that referenced this pull request Sep 18, 2018
This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.

PR-URL: #22556
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
targos pushed a commit that referenced this pull request Sep 19, 2018
This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.

PR-URL: #22556
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
targos pushed a commit that referenced this pull request Sep 20, 2018
This allows us to tell the type of the errors without using
instanceof, which is necessary in WPT harness.

PR-URL: #22556
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
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.

None yet

7 participants