@@ -16,12 +16,14 @@ import 'package:path/path.dart' as p;
1616
1717dynamic instantiateAnnotation (ElementAnnotationImpl annotation) {
1818 var annotationObjectImpl = annotation.evaluationResult.value;
19- if (annotationObjectImpl.hasKnownValue) {
20- try {
21- return _getValue (
22- annotationObjectImpl, annotation.element.context.typeProvider);
23- } on CannotCreateFromAnnotationException catch (_) {
24- // NOOP
19+ try {
20+ return _getValue (
21+ annotationObjectImpl, annotation.element.context.typeProvider);
22+ } on CannotCreateFromAnnotationException catch (e) {
23+ if (e.innerException != null ) {
24+ // If there was a issue creating a nested object, there's not much we
25+ // can do.
26+ rethrow ;
2527 }
2628 }
2729
@@ -81,34 +83,48 @@ dynamic _getValue(DartObject object, TypeProvider typeProvider) {
8183 object, 'object' , "Provided type value is not supported." );
8284 }
8385
84- var listValue = object.toListValue ();
85- if (listValue != null ) {
86- return listValue
87- .map ((DartObject element) => _getValue (element, typeProvider))
88- .toList ();
89- }
86+ try {
87+ var listValue = object.toListValue ();
88+ if (listValue != null ) {
89+ return listValue
90+ .map ((DartObject element) => _getValue (element, typeProvider))
91+ .toList ();
92+ }
9093
91- var mapValue = object.toMapValue ();
92- if (mapValue != null ) {
93- var result = {};
94- mapValue.forEach ((DartObject key, DartObject value) {
95- dynamic mappedKey = _getValue (key, typeProvider);
96- if (mappedKey != null ) {
97- result[mappedKey] = _getValue (value, typeProvider);
98- }
99- });
100- return result;
94+ var mapValue = object.toMapValue ();
95+ if (mapValue != null ) {
96+ var result = {};
97+ mapValue.forEach ((DartObject key, DartObject value) {
98+ dynamic mappedKey = _getValue (key, typeProvider);
99+ if (mappedKey != null ) {
100+ result[mappedKey] = _getValue (value, typeProvider);
101+ }
102+ });
103+ return result;
104+ }
105+ } on CannotCreateFromAnnotationException catch (e) {
106+ throw new CannotCreateFromAnnotationException ._(object, e);
101107 }
102108
103109 throw new CannotCreateFromAnnotationException ._(object);
104110}
105111
106112class CannotCreateFromAnnotationException {
107113 final DartObject object;
114+ final CannotCreateFromAnnotationException innerException;
108115
109- CannotCreateFromAnnotationException ._(this .object);
116+ CannotCreateFromAnnotationException ._(this .object, [ this .innerException] );
110117
111- String toString () => "Cannot create object from $object " ;
118+ String toString () {
119+ var buffer = new StringBuffer ("Cannot create object from ${object }" );
120+
121+ if (innerException != null ) {
122+ buffer.writeln ();
123+ buffer.write ('due to inner object: $innerException ' );
124+ }
125+
126+ return buffer.toString ();
127+ }
112128}
113129
114130final _cannotCreate = new Object ();
0 commit comments