Skip to content

Commit ee1b574

Browse files
pkozlowski-opensourcemhevery
authored andcommitted
fix(di): improve error messages for invalid bindings
Fixes angular#1515 Closes angular#1573
1 parent c0f3778 commit ee1b574

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

modules/angular2/src/di/exceptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class InvalidBindingError extends Error {
163163
message:string;
164164
constructor(binding) {
165165
super();
166-
this.message = `Invalid binding ${binding}`;
166+
this.message = `Invalid binding - only instances of Binding and Type are allowed, got: ${binding}`;
167167
}
168168

169169
toString():string {

modules/angular2/src/di/injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function _resolveBindings(bindings:List): List {
379379
} else if (unresolved instanceof List) {
380380
resolved = _resolveBindings(unresolved);
381381
} else if (unresolved instanceof BindingBuilder) {
382-
throw new InvalidBindingError(unresolved.token);
382+
throw new InvalidBindingError('BindingBuilder with ' + unresolved.token + ' token');
383383
} else {
384384
throw new InvalidBindingError(unresolved);
385385
}

modules/angular2/test/di/injector_spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ export function main() {
205205
});
206206

207207
it('should throw when given invalid bindings', function () {
208-
expect(() => Injector.resolveAndCreate(["blah"])).toThrowError('Invalid binding blah');
209-
expect(() => Injector.resolveAndCreate([bind("blah")])).toThrowError('Invalid binding blah');
208+
expect(() => Injector.resolveAndCreate(["blah"]))
209+
.toThrowError('Invalid binding - only instances of Binding and Type are allowed, got: blah');
210+
expect(() => Injector.resolveAndCreate([bind("blah")]))
211+
.toThrowError('Invalid binding - only instances of Binding and Type are allowed, ' +
212+
'got: BindingBuilder with blah token');
210213
});
211214

212215
it('should provide itself', function () {

0 commit comments

Comments
 (0)