feat(zone.js): add a zone config to allow user disable wrapping uncaught promise rejection#35873
feat(zone.js): add a zone config to allow user disable wrapping uncaught promise rejection#35873JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Conversation
343c9c5 to
170d334
Compare
There was a problem hiding this comment.
What is the benefit of throwing and than catching the error? If there is a reason, can you document it please so others are not confused like me.
There was a problem hiding this comment.
I believe the reason of the logic here is if the rejected value is not an Error object, we will build an Error object to add more readable message and stack trace.
eb0778a to
c95b5c4
Compare
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `rejection` property equals to the original error, and the message will be `Uncaught (in promise): testError....`, You can disable this wrapping behavior by defining a global configuraiton `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
c95b5c4 to
96f648c
Compare
|
FYI, changes in this PR were tested against g3 as a part of #36043, using Global TAP run, which was successful. Thank you. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Close #27840.
By default,
zone.jswrap uncaught promise error and wrap it to a new Error object with someadditional information includes the value of the error and the stack trace.
Consider the following example:
The
promise-errorzone catches a wrappedErrorobject whoserejectproperty equalsto the
originalError, and the message will beUncaught (in promise): testError....You can disable this wrapping behavior by defining a global configuraiton
__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;before importingzone.js.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #28740
This PR was original submitted here #31443, and it was reverted as it is a breaking change, and in this new PR, I changed the logic and keep the original behavior and use a configuration to let user change the behavior.