Uh oh!
There was an error while loading. Please reload this page.
doc: improve example for Error.captureStackTrace() - #46886
Conversation
BridgeAR
left a comment
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
Should we maybe add a suggestion to use |
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... |
There was a problem hiding this comment.
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.,
functiona(){b();}functionb(){c();}functionc(){// Create an error without stack trace to avoid calculating the stack trace twice.const{ stackTraceLimit }=Error;Error.stackTraceLimit=0;consterror=newError();Error.stackTraceLimit=stackTraceLimit;// Capture the stack trace above function bError.captureStackTrace(error,b);// Neither function c, nor b is included in the stack tracethrowerror;}That way we create a "real" error and only change it's stack trace accordingly.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
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 |
brodo
commented
Mar 14, 2023
Is there anything else I need to do to so this can get merged? |
Could you rebase and update the first commit message, it seems the description exceeds the size limit of 72 |
debadree25
left a comment
There was a problem hiding this comment.
The example looks good, would also wait for @BridgeAR 's review to see if the changes address all his concerns.
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 <ruben@bridgewater.de>
c4b05b3 to
7d8b38fComparebrodo
commented
Mar 18, 2023
I've squashed all the commits and added line breaks. |
nodejs-github-bot
commented
Mar 26, 2023
Landed in 38e6ac7 |
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 <ruben@bridgewater.de> PR-URL: #46886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
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 <ruben@bridgewater.de> PR-URL: #46886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
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 <ruben@bridgewater.de> PR-URL: #46886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
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 <ruben@bridgewater.de> PR-URL: #46886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Change the
MyErrorexample so that instances ofMyErrorareinstanceof Errorand also native errors when checked withutil.types.isNativeError().