Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 399db61

Browse files
committed
fix(promise): include stack trace in an unhandlerd promise
1 parent 473f01c commit 399db61

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Diff for: lib/zone.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ const Zone: ZoneType = (function(global: any) {
867867
if (this.data && typeof this.data.handleId !== 'undefined') {
868868
return this.data.handleId;
869869
} else {
870-
return this.toString();
870+
return Object.prototype.toString.call(this);
871871
}
872872
}
873873
}
@@ -994,7 +994,7 @@ const Zone: ZoneType = (function(global: any) {
994994
if (queue.length == 0 && state == REJECTED) {
995995
promise[symbolState] = REJECTED_NO_CATCH;
996996
try {
997-
throw new Error("Uncaught (in promise): " + value);
997+
throw new Error("Uncaught (in promise): " + value + (value && value.stack ? '\n' + value.stack : ''));
998998
} catch (e) {
999999
const error: UncaughtPromiseError = e;
10001000
error.rejection = value;

Diff for: test/common/Promise.spec.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ describe('Promise', ifEnvSupports('Promise', function () {
233233
var promiseError: Error = null;
234234
var zone: Zone = null;
235235
var task: Task = null;
236+
var error: Error = null;
236237
queueZone.fork({
237238
name: 'promise-error',
238239
onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone,
@@ -244,13 +245,15 @@ describe('Promise', ifEnvSupports('Promise', function () {
244245
}).run(() => {
245246
zone = Zone.current;
246247
task = Zone.currentTask;
247-
Promise.reject('rejectedErrorShouldBeHandled');
248+
error = new Error('rejectedErrorShouldBeHandled');
249+
Promise.reject(error);
248250
expect(promiseError).toBe(null);
249251
});
250252
setTimeout(() => null);
251253
setTimeout(() => {
252-
expect(promiseError.message).toBe('Uncaught (in promise): rejectedErrorShouldBeHandled');
253-
expect(promiseError['rejection']).toBe('rejectedErrorShouldBeHandled');
254+
expect(promiseError.message).toBe('Uncaught (in promise): ' + error +
255+
(error.stack ? '\n' + error.stack : ''));
256+
expect(promiseError['rejection']).toBe(error);
254257
expect(promiseError['zone']).toBe(zone);
255258
expect(promiseError['task']).toBe(task);
256259
done();

0 commit comments

Comments
 (0)