Skip to content

Commit eb0fd79

Browse files
committed
feat(di): changed InstantiationError to print the original stack
1 parent 56245c6 commit eb0fd79

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

modules/angular2/src/di/exceptions.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export class AbstractBindingError extends BaseException {
3636
keys: List<any>;
3737
constructResolvingMessage: Function;
3838
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
39-
constructor(key, constructResolvingMessage: Function) {
40-
super();
39+
constructor(key, constructResolvingMessage: Function, originalException?, originalStack?) {
40+
super(null, originalException, originalStack);
4141
this.keys = [key];
4242
this.constructResolvingMessage = constructResolvingMessage;
4343
this.message = this.constructResolvingMessage(this.keys);
@@ -138,19 +138,18 @@ export class CyclicDependencyError extends AbstractBindingError {
138138
* @exportedAs angular2/di_errors
139139
*/
140140
export class InstantiationError extends AbstractBindingError {
141-
cause;
142141
causeKey;
143-
stack;
144142

145143
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
146-
constructor(cause, stack, key) {
144+
constructor(originalException, originalStack, key) {
147145
super(key, function(keys: List<any>) {
148146
var first = stringify(ListWrapper.first(keys).token);
149-
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`;
150-
});
151-
this.cause = cause;
147+
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` +
148+
` ORIGINAL ERROR: ${originalException}` +
149+
`\n\n ORIGINAL STACK: ${originalStack}`;
150+
}, originalException, originalStack);
151+
152152
this.causeKey = key;
153-
this.stack = stack;
154153
}
155154
}
156155

modules/angular2/test/core/compiler/integration_dart_spec.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ main() {
5555
});
5656

5757
describe('Error handling', () {
58-
//TODO: vsavkin reenable this test after merging DI and EI
59-
xit('should preserve Error stack traces thrown from components', inject([
58+
it('should preserve Error stack traces thrown from components', inject([
6059
TestComponentBuilder,
6160
AsyncTestCompleter
6261
], (tb, async) {
@@ -65,13 +64,13 @@ main() {
6564
directives: [ThrowingComponent]))
6665

6766
.createAsync(Dummy).catchError((e, stack) {
68-
expect(stack.toString().split('\n')[0]).toEqual(e.message);
67+
expect(e.message).toContain("MockException");
68+
expect(e.message).toContain("functionThatThrows");
6969
async.done();
7070
});
7171
}));
7272

73-
//TODO: vsavkin reenable this test after merging DI and EI
74-
xit('should preserve non-Error stack traces thrown from components', inject([
73+
it('should preserve non-Error stack traces thrown from components', inject([
7574
TestComponentBuilder,
7675
AsyncTestCompleter
7776
], (tb, async) {
@@ -80,7 +79,8 @@ main() {
8079
directives: [ThrowingComponent2]))
8180

8281
.createAsync(Dummy).catchError((e, stack) {
83-
expect(stack.toString().split('\n')[0]).toEqual(e.message);
82+
expect(e.message).toContain("NonError");
83+
expect(e.message).toContain("functionThatThrows");
8484
async.done();
8585
});
8686
}));

modules/angular2/test/di/injector_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export function main() {
250250
} catch (e) {
251251
expect(e.message)
252252
.toContain(`Error during instantiation of Engine! (${stringify(Car)} -> Engine)`);
253-
expect(e.cause instanceof BaseException).toBeTruthy();
253+
expect(e.originalException instanceof BaseException).toBeTruthy();
254254
expect(e.causeKey.token).toEqual(Engine);
255255
}
256256
});

0 commit comments

Comments
 (0)