fix(di): capture original exception in InvalidBindingError
Fixes #1406 Closes #1459
This commit is contained in:
parent
fe70c2647a
commit
e23004df52
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue