Skip to content

Commit 53262f5

Browse files
committed
Make CheckedFromJsonException ctor public
Fixes #187
1 parent b71c92a commit 53262f5

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

json_annotation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 0.2.6
22

3+
* `CheckedFromJsonException`
4+
* The constructor is now public.
5+
* The `message` property is now `String` (instead of `Object`).
6+
37
* Added `JsonKey.defaultValue`.
48

59
* Added helpers for deserialization of `enum` values.

json_annotation/lib/src/checked_helpers.dart

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ T $checkedNew<T>(String className, Map map, T constructor(),
2323
if (error is ArgumentError) {
2424
key = fieldKeyMap[error.name] ?? error.name;
2525
}
26-
throw new CheckedFromJsonException._(error, stack, map, key,
26+
throw new CheckedFromJsonException(error, stack, map, key,
2727
className: className);
2828
}
2929
}
@@ -38,28 +38,44 @@ T $checkedConvert<T>(Map map, String key, T castFunc(Object value)) {
3838
} on CheckedFromJsonException {
3939
rethrow;
4040
} catch (error, stack) {
41-
throw new CheckedFromJsonException._(error, stack, map, key);
41+
throw new CheckedFromJsonException(error, stack, map, key);
4242
}
4343
}
4444

4545
/// Exception thrown if there is a runtime exception in `fromJson`
4646
/// code generated when `JsonSerializableGenerator.checked` is `true`
4747
class CheckedFromJsonException implements Exception {
48+
/// The [Error] or [Exception] that triggered this exception.
4849
final Object innerError;
50+
51+
/// The [StackTrace] for the [Error] or [Exception] that triggered this
52+
/// exception.
4953
final StackTrace innerStack;
54+
55+
/// The key from [map] that corresponds to the thrown [innerError].
56+
///
57+
/// May be `null`.
5058
final String key;
59+
60+
/// The source [Map] that was used for decoding when the [innerError] was
61+
/// thrown.
5162
final Map map;
52-
final Object message;
5363

54-
String _className;
64+
/// A human-readable message corresponding to [innerError].
65+
///
66+
/// May be `null`.
67+
final String message;
68+
69+
/// The name of the class being created when [innerError] was thrown.
5570
String get className => _className;
71+
String _className;
5672

57-
CheckedFromJsonException._(
58-
this.innerError, this.innerStack, this.map, this.key,
73+
/// Creates a new instance of [CheckedFromJsonException].
74+
CheckedFromJsonException(this.innerError, this.innerStack, this.map, this.key,
5975
{String className})
6076
: _className = className,
6177
message = _getMessage(innerError);
6278

63-
static Object _getMessage(Object error) =>
64-
(error is ArgumentError) ? error.message : null;
79+
static String _getMessage(Object error) =>
80+
(error is ArgumentError) ? error.message?.toString() : null;
6581
}

0 commit comments

Comments
 (0)