diff --git a/modules/angular2/src/di/exceptions.js b/modules/angular2/src/di/exceptions.js index ffc9da8234..ed0c59838c 100644 --- a/modules/angular2/src/di/exceptions.js +++ b/modules/angular2/src/di/exceptions.js @@ -140,13 +140,17 @@ export class CyclicDependencyError extends AbstractBindingError { * @exportedAs angular2/di_errors */ export class InstantiationError extends AbstractBindingError { + cause; + causeKey; // TODO(tbosch): Can't do key:Key as this results in a circular dependency! - constructor(originalException, key) { + constructor(cause, key) { super(key, function (keys:List) { var first = stringify(ListWrapper.first(keys).token); return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` + - ` ORIGINAL ERROR: ${originalException}`; + ` ORIGINAL ERROR: ${cause}`; }); + this.cause = cause; + this.causeKey = key; } } diff --git a/modules/angular2/test/di/injector_spec.js b/modules/angular2/test/di/injector_spec.js index b31e72a171..8bd11f2a1e 100644 --- a/modules/angular2/test/di/injector_spec.js +++ b/modules/angular2/test/di/injector_spec.js @@ -1,4 +1,4 @@ -import {isBlank} from 'angular2/src/facade/lang'; +import {isBlank, BaseException} from 'angular2/src/facade/lang'; import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib'; import {Injector, Inject, InjectLazy, Optional, bind, ResolvedBinding} from 'angular2/di'; @@ -7,7 +7,7 @@ class Engine { class BrokenEngine { constructor() { - throw "Broken Engine"; + throw new BaseException("Broken Engine"); } } @@ -251,6 +251,8 @@ export function main() { throw "Must throw"; } catch (e) { expect(e.message).toContain("Error during instantiation of Engine! (Car -> Engine)"); + expect(e.cause instanceof BaseException).toBeTruthy(); + expect(e.causeKey.token).toEqual(Engine); } });