diff --git a/modules/angular2/src/di/exceptions.ts b/modules/angular2/src/di/exceptions.ts index a514ce1956..acffbbb4fd 100644 --- a/modules/angular2/src/di/exceptions.ts +++ b/modules/angular2/src/di/exceptions.ts @@ -36,8 +36,8 @@ export class AbstractBindingError extends BaseException { keys: List; constructResolvingMessage: Function; // TODO(tbosch): Can't do key:Key as this results in a circular dependency! - constructor(key, constructResolvingMessage: Function) { - super(); + constructor(key, constructResolvingMessage: Function, originalException?, originalStack?) { + super(null, originalException, originalStack); this.keys = [key]; this.constructResolvingMessage = constructResolvingMessage; this.message = this.constructResolvingMessage(this.keys); @@ -138,19 +138,18 @@ export class CyclicDependencyError extends AbstractBindingError { * @exportedAs angular2/di_errors */ export class InstantiationError extends AbstractBindingError { - cause; causeKey; - stack; // TODO(tbosch): Can't do key:Key as this results in a circular dependency! - constructor(cause, stack, key) { + constructor(originalException, originalStack, key) { super(key, function(keys: List) { var first = stringify(ListWrapper.first(keys).token); - return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`; - }); - this.cause = cause; + return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` + + ` ORIGINAL ERROR: ${originalException}` + + `\n\n ORIGINAL STACK: ${originalStack}`; + }, originalException, originalStack); + this.causeKey = key; - this.stack = stack; } } diff --git a/modules/angular2/test/core/compiler/integration_dart_spec.dart b/modules/angular2/test/core/compiler/integration_dart_spec.dart index 4f0091bf66..64c9c7bdce 100644 --- a/modules/angular2/test/core/compiler/integration_dart_spec.dart +++ b/modules/angular2/test/core/compiler/integration_dart_spec.dart @@ -55,8 +55,7 @@ main() { }); describe('Error handling', () { - //TODO: vsavkin reenable this test after merging DI and EI - xit('should preserve Error stack traces thrown from components', inject([ + it('should preserve Error stack traces thrown from components', inject([ TestComponentBuilder, AsyncTestCompleter ], (tb, async) { @@ -65,13 +64,13 @@ main() { directives: [ThrowingComponent])) .createAsync(Dummy).catchError((e, stack) { - expect(stack.toString().split('\n')[0]).toEqual(e.message); + expect(e.message).toContain("MockException"); + expect(e.message).toContain("functionThatThrows"); async.done(); }); })); - //TODO: vsavkin reenable this test after merging DI and EI - xit('should preserve non-Error stack traces thrown from components', inject([ + it('should preserve non-Error stack traces thrown from components', inject([ TestComponentBuilder, AsyncTestCompleter ], (tb, async) { @@ -80,7 +79,8 @@ main() { directives: [ThrowingComponent2])) .createAsync(Dummy).catchError((e, stack) { - expect(stack.toString().split('\n')[0]).toEqual(e.message); + expect(e.message).toContain("NonError"); + expect(e.message).toContain("functionThatThrows"); async.done(); }); })); diff --git a/modules/angular2/test/di/injector_spec.ts b/modules/angular2/test/di/injector_spec.ts index be54026726..4921b6f312 100644 --- a/modules/angular2/test/di/injector_spec.ts +++ b/modules/angular2/test/di/injector_spec.ts @@ -250,7 +250,7 @@ export function main() { } catch (e) { expect(e.message) .toContain(`Error during instantiation of Engine! (${stringify(Car)} -> Engine)`); - expect(e.cause instanceof BaseException).toBeTruthy(); + expect(e.originalException instanceof BaseException).toBeTruthy(); expect(e.causeKey.token).toEqual(Engine); } });