Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 2402c47

Browse files
committed
Revert "fix(zone.js): do not silence uncaught promise rejections when the finally is called (angular#45449)" (angular#46461)
This reverts commit cb57cdb. PR Close angular#46461
1 parent 63396a1 commit 2402c47

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

packages/zone.js/lib/common/promise.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
249249
function scheduleResolveOrReject<R, U1, U2>(
250250
promise: ZoneAwarePromise<any>, zone: Zone, chainPromise: ZoneAwarePromise<any>,
251251
onFulfilled?: ((value: R) => U1)|null|undefined,
252-
onRejected?: ((error: any) => U2)|null|undefined, scheduledByFinally = false): void {
253-
// Note: the native promise implementation logs unhandled promise rejections after `onFinally`
254-
// has been called. We may rely on the `scheduledByFinally` argument, which is `false` by
255-
// default, to avoid creating a breaking change; this will also allow us to reduce the number of
256-
// changes. The `finally` function should not silence unhandled promise rejections, because
257-
// they're not silenced in any implementation. If the `scheduleResolveOrReject` is called within
258-
// the `finally` we won't clear unhandled rejections. We'll keep the same behaviour if the
259-
// `scheduleResolveOrReject` is called within the `then`.
260-
if (!scheduledByFinally) {
261-
clearRejectedNoCatch(promise);
262-
}
252+
onRejected?: ((error: any) => U2)|null|undefined): void {
253+
clearRejectedNoCatch(promise);
263254
const promiseState = (promise as any)[symbolState];
264255
const delegate = promiseState ?
265256
(typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
@@ -515,8 +506,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
515506
if ((this as any)[symbolState] == UNRESOLVED) {
516507
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFinally, onFinally);
517508
} else {
518-
scheduleResolveOrReject(
519-
this, zone, chainPromise as any, onFinally, onFinally, /* scheduledByFinally */ true);
509+
scheduleResolveOrReject(this, zone, chainPromise as any, onFinally, onFinally);
520510
}
521511
return chainPromise;
522512
}

packages/zone.js/test/common/Promise.spec.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,6 @@ describe(
376376
});
377377
});
378378

379-
it('should not silence rejected promise errors after .finally has been called', done => {
380-
Zone.current.fork({name: 'promise-error'}).run(() => {
381-
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = false;
382-
const originalConsoleError = console.error;
383-
const spy = console.error = jasmine.createSpy('console.error');
384-
new Promise((resolve, reject) => {
385-
throw new Error('promise error');
386-
}).finally(() => {
387-
// Ensure that uncaught promise `console.error` is called after the `finally` is
388-
// called.
389-
expect(spy).not.toHaveBeenCalled();
390-
setTimeout(() => {
391-
const {args} = spy.calls.mostRecent();
392-
expect(args).toContain('Unhandled Promise rejection:');
393-
expect(args).toContain('promise error');
394-
console.error = originalConsoleError;
395-
done();
396-
}, 10);
397-
});
398-
});
399-
});
400-
401379
it('should not output error to console if ignoreConsoleErrorUncaughtError is true',
402380
(done) => {
403381
Zone.current.fork({name: 'promise-error'}).run(() => {

0 commit comments

Comments
 (0)