-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
C++ errors and JS errors format mismatch #26669
Comments
I think there was some previous discussion (somewhere?) that it’s a bad idea to modify the |
Possibly a duplicate of #20253? I'd be in favor of a breaking change that moves the codes out of the |
It indeed looks like a duplicate of #20253. I personally would also like to change it to only contain the class name. One way that work relatively well is: #20253 (comment) An alternative would be to move it in the message property as suggested in #20253 (comment) |
I tried restoring the name property and moving the code out of them once, but there were too many tests failing because we explicitly test for the name property with this format (there are still 77 tests on the current master if you search for Maybe we should start migrating those tests? We already disable this format for WPT with |
@joyeecheung I would be rigorous in this case and use regular expressions to replace these cases. It would otherwise indeed be a lot of work to change all these tests. I am not sure how you would like to migrate the tests without having to change all at once (if we want to keep on using |
@BridgeAR Pretty sure for most cases (errors that are not thrown from a different vm context), we could just replace
with
For errors thrown from another context, we could switch to regular expressions, but those are rare. No matter how we change those tests, there are still going to be 70+ files to be changed so I don't see a huge difference. |
@joyeecheung I don't think it is a good idea to use The only reason why I originally added this functionality was that |
Right, |
@BridgeAR The issue with |
@joyeecheung this is the only special case and we'd run into the same issue with |
@BridgeAR But we could extend |
I like the common. APIs. Every time I type |
@sam-github you could use |
@BridgeAR Nice idea, I just tried, but it triggers our eslint error. |
Yes, we should improve the rule to detect that. |
I have a fix with which the errors will always print the same as they do right now but with which the name is set to the class name. I'll open a PR for it later on. |
When using `Errors.captureStackFrames` the error's stack property is set again. This adds a helper function that wraps this functionality in a simple API that does not only set the stack including the `code` property but it also improves the performance to create the error. The helper works for thrown errors and errors returned from wrapped functions in case they are Node.js core errors. PR-URL: nodejs#26738 Fixes: nodejs#26669 Fixes: nodejs#20253 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
This is a first step to align the n-api errors towards errors created in JS. The stack still has to be updated to add the error code. PR-URL: nodejs#26738 Fixes: nodejs#26669 Fixes: nodejs#20253 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
The format of the
name
property differs between errors generated by C++ and those generated by JS.For example, JS errors will contain a
name
like'TypeError [ERR_FOO_BAR_BAZ]'
, while C++ errors will contain aname
with just'TypeError'
.It's probably a good idea to have these two match.
The text was updated successfully, but these errors were encountered: