This reverts commit 2bb9a65351
.
It breaks tests in google3 which rely on the error handling behavior.
PR Close #31918
This commit is contained in:
parent
185b3dd08e
commit
975917bafd
|
@ -176,25 +176,20 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
|
||||||
}
|
}
|
||||||
if (queue.length == 0 && state == REJECTED) {
|
if (queue.length == 0 && state == REJECTED) {
|
||||||
(promise as any)[symbolState] = REJECTED_NO_CATCH;
|
(promise as any)[symbolState] = REJECTED_NO_CATCH;
|
||||||
let uncaughtPromiseError: any;
|
try {
|
||||||
if (value instanceof Error || (value && value.message)) {
|
// try to print more readable error log
|
||||||
uncaughtPromiseError = value;
|
throw new Error(
|
||||||
} else {
|
'Uncaught (in promise): ' + readableObjectToString(value) +
|
||||||
try {
|
(value && value.stack ? '\n' + value.stack : ''));
|
||||||
// try to print more readable error log
|
} catch (err) {
|
||||||
throw new Error(
|
const error: UncaughtPromiseError = err;
|
||||||
'Uncaught (in promise): ' + readableObjectToString(value) +
|
error.rejection = value;
|
||||||
(value && value.stack ? '\n' + value.stack : ''));
|
error.promise = promise;
|
||||||
} catch (err) {
|
error.zone = Zone.current;
|
||||||
uncaughtPromiseError = err;
|
error.task = Zone.currentTask !;
|
||||||
}
|
_uncaughtPromiseErrors.push(error);
|
||||||
|
api.scheduleMicroTask(); // to make sure that it is running
|
||||||
}
|
}
|
||||||
uncaughtPromiseError.rejection = value;
|
|
||||||
uncaughtPromiseError.promise = promise;
|
|
||||||
uncaughtPromiseError.zone = Zone.current;
|
|
||||||
uncaughtPromiseError.task = Zone.currentTask !;
|
|
||||||
_uncaughtPromiseErrors.push(uncaughtPromiseError);
|
|
||||||
api.scheduleMicroTask(); // to make sure that it is running
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,8 +345,11 @@ describe(
|
||||||
});
|
});
|
||||||
setTimeout((): any => null);
|
setTimeout((): any => null);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
expect(promiseError !.message)
|
||||||
|
.toBe(
|
||||||
|
'Uncaught (in promise): ' + error +
|
||||||
|
(error !.stack ? '\n' + error !.stack : ''));
|
||||||
expect((promiseError as any)['rejection']).toBe(error);
|
expect((promiseError as any)['rejection']).toBe(error);
|
||||||
expect(promiseError).toBe(error);
|
|
||||||
expect((promiseError as any)['zone']).toBe(zone);
|
expect((promiseError as any)['zone']).toBe(zone);
|
||||||
expect((promiseError as any)['task']).toBe(task);
|
expect((promiseError as any)['task']).toBe(task);
|
||||||
done();
|
done();
|
||||||
|
@ -386,39 +389,6 @@ describe(
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should print original information when throw a not error object with a message property',
|
|
||||||
(done) => {
|
|
||||||
let promiseError: Error|null = null;
|
|
||||||
let zone: Zone|null = null;
|
|
||||||
let task: Task|null = null;
|
|
||||||
let rejectObj: TestRejection;
|
|
||||||
queueZone
|
|
||||||
.fork({
|
|
||||||
name: 'promise-error',
|
|
||||||
onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any):
|
|
||||||
boolean => {
|
|
||||||
promiseError = error;
|
|
||||||
delegate.handleError(target, error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.run(() => {
|
|
||||||
zone = Zone.current;
|
|
||||||
task = Zone.currentTask;
|
|
||||||
rejectObj = new TestRejection();
|
|
||||||
rejectObj.prop1 = 'value1';
|
|
||||||
rejectObj.prop2 = 'value2';
|
|
||||||
(rejectObj as any).message = 'rejectMessage';
|
|
||||||
Promise.reject(rejectObj);
|
|
||||||
expect(promiseError).toBe(null);
|
|
||||||
});
|
|
||||||
setTimeout((): any => null);
|
|
||||||
setTimeout(() => {
|
|
||||||
expect(promiseError).toEqual(rejectObj as any);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Promise.race', () => {
|
describe('Promise.race', () => {
|
||||||
it('should reject the value', () => {
|
it('should reject the value', () => {
|
||||||
queueZone.run(() => {
|
queueZone.run(() => {
|
||||||
|
|
|
@ -84,7 +84,9 @@ describe('FakeAsyncTestZoneSpec', () => {
|
||||||
() => {
|
() => {
|
||||||
fakeAsyncTestZone.run(() => {
|
fakeAsyncTestZone.run(() => {
|
||||||
Promise.resolve(null).then((_) => { throw new Error('async'); });
|
Promise.resolve(null).then((_) => { throw new Error('async'); });
|
||||||
expect(() => { testZoneSpec.flushMicrotasks(); }).toThrowError(/async/);
|
expect(() => {
|
||||||
|
testZoneSpec.flushMicrotasks();
|
||||||
|
}).toThrowError(/Uncaught \(in promise\): Error: async/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1169,7 +1171,7 @@ const {fakeAsync, tick, discardPeriodicTasks, flush, flushMicrotasks} = fakeAsyn
|
||||||
resolvedPromise.then((_) => { throw new Error('async'); });
|
resolvedPromise.then((_) => { throw new Error('async'); });
|
||||||
flushMicrotasks();
|
flushMicrotasks();
|
||||||
})();
|
})();
|
||||||
}).toThrowError(/async/);
|
}).toThrowError(/Uncaught \(in promise\): Error: async/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should complain if a test throws an exception', () => {
|
it('should complain if a test throws an exception', () => {
|
||||||
|
|
Loading…
Reference in New Issue