Skip to content

Commit 197cf09

Browse files
committed
feat(core): improve NoAnnotationError message
Closes #4866 Closes #5927
1 parent e67ebb7 commit 197cf09

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

modules/angular2/src/core/di/exceptions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ export class NoAnnotationError extends BaseException {
222222
signature.push(parameter.map(stringify).join(' '));
223223
}
224224
}
225-
return "Cannot resolve all parameters for " + stringify(typeOrFunc) + "(" +
226-
signature.join(', ') + "). " + 'Make sure they all have valid type or annotations.';
225+
return "Cannot resolve all parameters for '" + stringify(typeOrFunc) + "'(" +
226+
signature.join(', ') + "). " +
227+
"Make sure that all the parameters are decorated with Inject or have valid type annotations and that '" +
228+
stringify(typeOrFunc) + "' is decorated with Injectable.";
227229
}
228230
}
229231

modules/angular2/test/core/di/injector_spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class NoAnnotations {
8888
constructor(secretDependency) {}
8989
}
9090

91+
function factoryFn(a) {}
92+
9193
export function main() {
9294
var dynamicProviders = [
9395
provide('provider0', {useValue: 1}),
@@ -142,10 +144,20 @@ export function main() {
142144
expect(car.engine).toBeAnInstanceOf(TurboEngine);
143145
});
144146

145-
it('should throw when no type and not @Inject', () => {
147+
it('should throw when no type and not @Inject (class case)', () => {
146148
expect(() => createInjector([NoAnnotations]))
147-
.toThrowError('Cannot resolve all parameters for NoAnnotations(?). ' +
148-
'Make sure they all have valid type or annotations.');
149+
.toThrowError(
150+
"Cannot resolve all parameters for 'NoAnnotations'(?). " +
151+
'Make sure that all the parameters are decorated with Inject or have valid type annotations ' +
152+
"and that 'NoAnnotations' is decorated with Injectable.");
153+
});
154+
155+
it('should throw when no type and not @Inject (factory case)', () => {
156+
expect(() => createInjector([provide("someToken", {useFactory: factoryFn})]))
157+
.toThrowError(
158+
"Cannot resolve all parameters for 'factoryFn'(?). " +
159+
'Make sure that all the parameters are decorated with Inject or have valid type annotations ' +
160+
"and that 'factoryFn' is decorated with Injectable.");
149161
});
150162

151163
it('should cache instances', () => {

0 commit comments

Comments
 (0)