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

fix(promise): include stack trace in an unhandlerd promise #463

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ const Zone: ZoneType = (function(global: any) {
if (this.data && typeof this.data.handleId !== 'undefined') {
return this.data.handleId;
} else {
return this.toString();
return Object.prototype.toString.call(this);
}
}
}
Expand Down Expand Up @@ -994,7 +994,7 @@ const Zone: ZoneType = (function(global: any) {
if (queue.length == 0 && state == REJECTED) {
promise[symbolState] = REJECTED_NO_CATCH;
try {
throw new Error("Uncaught (in promise): " + value);
throw new Error("Uncaught (in promise): " + value + (value && value.stack ? '\n' + value.stack : ''));
} catch (e) {
const error: UncaughtPromiseError = e;
error.rejection = value;
Expand Down
13 changes: 10 additions & 3 deletions test/common/Promise.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ describe('Promise', ifEnvSupports('Promise', function () {
var promiseError: Error = null;
var zone: Zone = null;
var task: Task = null;
var error: Error = null;
queueZone.fork({
name: 'promise-error',
onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone,
Expand All @@ -244,13 +245,19 @@ describe('Promise', ifEnvSupports('Promise', function () {
}).run(() => {
zone = Zone.current;
task = Zone.currentTask;
Promise.reject('rejectedErrorShouldBeHandled');
error = new Error('rejectedErrorShouldBeHandled');
try {
// throw so that the stack trace is captured
throw error;
} catch (e) {}
Promise.reject(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the expectation that promiseError is null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps, that was on accident, will add it back.

expect(promiseError).toBe(null);
});
setTimeout(() => null);
setTimeout(() => {
expect(promiseError.message).toBe('Uncaught (in promise): rejectedErrorShouldBeHandled');
expect(promiseError['rejection']).toBe('rejectedErrorShouldBeHandled');
expect(promiseError.message).toBe('Uncaught (in promise): ' + error +
(error.stack ? '\n' + error.stack : ''));
expect(promiseError['rejection']).toBe(error);
expect(promiseError['zone']).toBe(zone);
expect(promiseError['task']).toBe(task);
done();
Expand Down
2 changes: 1 addition & 1 deletion test/zone-spec/fake-async-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('FakeAsyncTestZoneSpec', () => {
fakeAsyncTestZone.run(() => {
Promise.resolve(null).then((_) => { throw new Error('async'); });
expect(() => { testZoneSpec.flushMicrotasks(); })
.toThrowError('Uncaught (in promise): Error: async');
.toThrowError(/Uncaught \(in promise\): Error: async/);
});
});

Expand Down