Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion json_serializable/lib/src/helper_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ $converterOrKeyInstructions
* Set `JsonSerializable.genericArgumentFactories` to `true`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html''';
} else if (field.type != error.type) {
message = '$message because of type `${typeToCode(error.type)}`';
try {
message = '$message because of type `${typeToCode(error.type)}`';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid doing a catch without details. What type is thrown? Unimplemented? From which type?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, specifically this line is throwing the error

package:json_serializable/src/utils.dart 221:3

throw UnimplementedError('(${type.runtimeType}) $type');

For me type.runtimeType is equal to InvalidTypeImpl when printed in the error.

Would you prefer a refactor like this:

try {
      message = '$message because of type `${typeToCode(error.type)}`';
} on UnimplementedError catch (ex) {
     message = '$message because type is Unimplemented ($ex)';
}

} catch (ex) {
message = '$message because of type is unimplemented/unsupported/undefined';
}
} else {
final element = error.type.element?.name;
todo = '''
Expand Down
Loading