GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||
GeezerVison is showing github.com — doc: improve example for Error.captureStackTrace() by brodo · Pull Request #46886 · nodejs/node Conversation
Contributor
Change the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
BridgeAR
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why you suggest this. I am not certain if the example becomes more difficult to read though, especially as it has new implications as outlined in my comment.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Should we maybe add a suggestion to use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I understand the readability concern. Essentially it's a trade-off between having a 'copyable' example and a readable one. It would be interesting to find out if there are packages on npm that contain this error implementation... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am hesitant to change the documentation like that as we mix different APIs and errors should ideally not be created like that in the first place.
What about changing the example to show how to hide multiple call sites? E.g.,
function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; }
That way we create a "real" error and only change it's stack trace accordingly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I like this example a lot. It illustrates the usage of the function much better. But shouldn't the last line be |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is there anything else I need to do to so this can get merged? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Could you rebase and update the first commit message, it seems the description exceeds the size limit of 72 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The example looks good, would also wait for @BridgeAR 's review to see if the changes address all his concerns.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Change the `MyError` example so that instances of `MyError`are `instanceof Error` and also native errors when checked with `util.types.isNativeError()`. Co-authored-by: Ruben Bridgewater <[email protected]>
c4b05b3 to
7d8b38f
Compare
I've squashed all the commits and added line breaks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 38e6ac7 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Change the `MyError` example so that instances of `MyError`are `instanceof Error` and also native errors when checked with `util.types.isNativeError()`. Co-authored-by: Ruben Bridgewater <[email protected]> PR-URL: #46886 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Change the `MyError` example so that instances of `MyError`are `instanceof Error` and also native errors when checked with `util.types.isNativeError()`. Co-authored-by: Ruben Bridgewater <[email protected]> PR-URL: #46886 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Change the `MyError` example so that instances of `MyError`are `instanceof Error` and also native errors when checked with `util.types.isNativeError()`. Co-authored-by: Ruben Bridgewater <[email protected]> PR-URL: #46886 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Change the `MyError` example so that instances of `MyError`are `instanceof Error` and also native errors when checked with `util.types.isNativeError()`. Co-authored-by: Ruben Bridgewater <[email protected]> PR-URL: #46886 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.