Skip to content

Commit dd3b7bb

Browse files
committed
feature(json_annotation): get the message from FormatException
Improves error output with improperly formatted URIs, for example Fixes #233
1 parent 0549d74 commit dd3b7bb

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

json_annotation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.9
2+
3+
* When `FormatException` is caught in "checked mode", use the `message`
4+
property when creating `CheckedFromJsonException`.
5+
16
## 0.2.8
27

38
* Added `$checkKeys` helper function and deprecated `$checkAllowedKeys`.

json_annotation/lib/src/checked_helpers.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class CheckedFromJsonException implements Exception {
9696
return error.message?.toString();
9797
} else if (error is BadKeyException) {
9898
return error.message;
99+
} else if (error is FormatException) {
100+
var message = error.message;
101+
if (error.offset != null) {
102+
message = '$message at offset ${error.offset}.';
103+
}
104+
return message;
99105
}
100106
return null;
101107
}

json_annotation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_annotation
2-
version: 0.2.8
2+
version: 0.2.9-dev
33
description: >-
44
Classes and helper functions that support JSON code generation via the
55
`json_serializable` package.

json_serializable/pubspec.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313

1414
# Use a tight version constraint to ensure that a constraint on
1515
# `json_annotation`. Properly constrains all features it provides.
16-
json_annotation: '>=0.2.8 <0.2.9'
16+
json_annotation: '>=0.2.9 <0.2.10'
1717
meta: ^1.1.0
1818
path: ^1.3.2
1919
source_gen: ^0.8.2
@@ -27,3 +27,7 @@ dev_dependencies:
2727
logging: ^0.11.3+1
2828
test: ^1.0.0
2929
yaml: ^2.1.13
30+
31+
dependency_overrides:
32+
json_annotation:
33+
path: ../json_annotation

json_serializable/test/yaml/yaml_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ builders:
140140
builder_name:
141141
builder_factories: ["scssBuilder"]
142142
configLocation: "user@host:invalid/uri"''':
143-
'''line 4, column 21 of file.yaml: Could not create `Builder`. Unsupported value for `configLocation`.
143+
'''line 4, column 21 of file.yaml: Could not create `Builder`. Unsupported value for `configLocation`. Illegal scheme character at offset 4.
144144
configLocation: "user@host:invalid/uri"
145145
^^^^^^^^^^^^^^^^^^^^^^^'''
146146
};

0 commit comments

Comments
 (0)