Skip to content

Commit 62b1a08

Browse files
committed
refactor(reflection): improved error message
1 parent c54f5e0 commit 62b1a08

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

modules/angular2/src/reflection/reflection_capabilities.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library reflection.reflection_capabilities;
22

33
import 'reflection.dart';
4+
import 'package:angular2/src/facade/lang.dart';
45
import 'types.dart';
56
import 'dart:mirrors';
67

@@ -45,7 +46,7 @@ class ReflectionCapabilities {
4546
create(name, [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]).reflectee;
4647
}
4748

48-
throw "Factory cannot take more than 10 arguments";
49+
throw "Cannot create a factory for '${stringify(type)}' because its constructor has more than 10 arguments";
4950
}
5051

5152
List<List> parameters(typeOrFunc) {

modules/angular2/src/reflection/reflection_capabilities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Type, isPresent, global} from 'angular2/src/facade/lang';
1+
import {Type, isPresent, global, stringify} from 'angular2/src/facade/lang';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
33
import {GetterFn, SetterFn, MethodFn} from './types';
44

@@ -39,7 +39,8 @@ export class ReflectionCapabilities {
3939
};
4040
};
4141

42-
throw new Error("Factory cannot take more than 10 arguments");
42+
throw new Error(
43+
`Cannot create a factory for '${stringify(t)}' because its constructor has more than 10 arguments`);
4344
}
4445

4546
_zipTypesAndAnnotaions(paramTypes, paramAnnotations): List<List<any>> {

modules/angular2/test/core/compiler/reflection_capabilities_spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ export function main() {
3131
}
3232

3333
describe('reflection capabilities', () => {
34+
describe("factory", () => {
35+
it("should create a factory for a type", () => {
36+
var f = rc.factory(ClassWithField);
37+
expect(f("value").field).toEqual("value");
38+
});
39+
40+
it("should throw when a constructor has more than 10 args", () => {
41+
expect(() => rc.factory(ClassWith11Fields)).toThrowError(
42+
new RegExp(`has more than 10 arguments`));
43+
});
44+
});
45+
3446
it('can read out class annotations through annotations key', () => {
3547
assertTestClassAnnotations(rc.annotations(TestClass));
3648
});
@@ -115,6 +127,17 @@ class TestClassTypesOnly {
115127
constructor(a: P1, b: P2) {}
116128
}
117129

130+
class ClassWithField {
131+
field;
132+
constructor(field) {
133+
this.field = field;
134+
}
135+
}
136+
class ClassWith11Fields {
137+
constructor(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) {
138+
}
139+
}
140+
118141
// Mocking the data stored in global.Reflect as if TS was compiling TestClass above.
119142
var mockDataForTestClassTypesOnly = {
120143
'annotations': null,

0 commit comments

Comments
 (0)