Skip to content

Commit 6d7eb35

Browse files
committed
fix(zone.js): disable wrapping unhandled promise error by default
Before this commit, zone.js wraps the uncaught promise rejection error to a new Error object includes more information such as Zone stack traces. This feature is provided from the very beginning of Zone.js, but this feature becomes very annoying and make the user difficult to debug. So this commit disable this wrapping behavior by default, and user can enable this feature back by setting `DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION` to `false`.
1 parent 664099b commit 6d7eb35

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

packages/platform-browser/test/testing_public_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ describe('public testing API', () => {
860860
})));
861861

862862
itPromise.then(() => done.fail('Expected test to fail, but it did not'), (err) => {
863-
expect(err.message).toEqual('Uncaught (in promise): baz');
863+
expect(err.message).toEqual('baz');
864864
done();
865865
});
866866
restoreJasmineIt();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
2323
const __symbol__ = api.symbol;
2424
const _uncaughtPromiseErrors: UncaughtPromiseError[] = [];
2525
const isDisableWrappingUncaughtPromiseRejection =
26-
global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] === true;
26+
global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] !== false;
2727
const symbolPromise = __symbol__('Promise');
2828
const symbolThen = __symbol__('then');
2929
const creationTrace = '__creationTrace__';

packages/zone.js/lib/zone.configurations.api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@ interface ZoneGlobalConfigurations {
576576
/**
577577
* Disable wrapping uncaught promise rejection.
578578
*
579-
* By default, `zone.js` wraps the uncaught promise rejection in a new `Error` object
580-
* which contains additional information such as a value of the rejection and a stack trace.
579+
* By default, `zone.js` throws the original error occurs in the uncaught promise rejection.
581580
*
582-
* If you set `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before
583-
* importing `zone.js`, `zone.js` will not wrap the uncaught promise rejection.
581+
* If you set `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = false;` before
582+
* importing `zone.js`, `zone.js` will wrap the uncaught promise rejection in a new `Error` object
583+
* which contains additional information such as a value of the rejection and a stack trace.
584584
*/
585585
__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION?: boolean;
586586
}

packages/zone.js/test/browser-zone-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (typeof window !== 'undefined') {
99
const zoneSymbol = (window as any).Zone.__symbol__;
1010
(window as any)['__Zone_enable_cross_context_check'] = true;
1111
(window as any)[zoneSymbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] = true;
12+
(window as any)[zoneSymbol('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] = false;
1213
}
1314
import '../lib/common/to-string';
1415
import '../lib/browser/api-util';

packages/zone.js/test/browser_disable_wrap_uncaught_promise_rejection_setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
(window as any)['__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION'] = true;
8+
// This is an empty karma test entry file just to keep the bazel macro happy.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
(window as any).global = window;
22
// Change default symbol prefix for testing to ensure no hard-coded references.
33
(window as any)['__Zone_symbol_prefix'] = '_test__';
4+
(window as any)['_test__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION'] = false;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// Change default symbol prefix for testing to ensure no hard-coded references.
22
(global as any)['__Zone_symbol_prefix'] = '__zone_symbol_test__';
3+
(global as any)['__zone_symbol_test__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION'] = false;

0 commit comments

Comments
 (0)