Skip to content

Commit e23004d

Browse files
fix(di): capture original exception in InvalidBindingError
Fixes angular#1406 Closes angular#1459
1 parent fe70c26 commit e23004d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

modules/angular2/src/di/exceptions.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,17 @@ export class CyclicDependencyError extends AbstractBindingError {
140140
* @exportedAs angular2/di_errors
141141
*/
142142
export class InstantiationError extends AbstractBindingError {
143+
cause;
144+
causeKey;
143145
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
144-
constructor(originalException, key) {
146+
constructor(cause, key) {
145147
super(key, function (keys:List) {
146148
var first = stringify(ListWrapper.first(keys).token);
147149
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` +
148-
` ORIGINAL ERROR: ${originalException}`;
150+
` ORIGINAL ERROR: ${cause}`;
149151
});
152+
this.cause = cause;
153+
this.causeKey = key;
150154
}
151155
}
152156

modules/angular2/test/di/injector_spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isBlank} from 'angular2/src/facade/lang';
1+
import {isBlank, BaseException} from 'angular2/src/facade/lang';
22
import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib';
33
import {Injector, Inject, InjectLazy, Optional, bind, ResolvedBinding} from 'angular2/di';
44

@@ -7,7 +7,7 @@ class Engine {
77

88
class BrokenEngine {
99
constructor() {
10-
throw "Broken Engine";
10+
throw new BaseException("Broken Engine");
1111
}
1212
}
1313

@@ -251,6 +251,8 @@ export function main() {
251251
throw "Must throw";
252252
} catch (e) {
253253
expect(e.message).toContain("Error during instantiation of Engine! (Car -> Engine)");
254+
expect(e.cause instanceof BaseException).toBeTruthy();
255+
expect(e.causeKey.token).toEqual(Engine);
254256
}
255257
});
256258

0 commit comments

Comments
 (0)