Skip to content

Commit 7d670c2

Browse files
bors[bot]jonasbb
andauthored
Merge #586
586: Improve error messaged by dropping untagged enums r=jonasbb a=jonasbb Untagged enums do not provide good error messages and likely never will, given that there are multiple PRs which are just completely ignored ([serde#2376](serde-rs/serde#2376) and [serde#1544](serde-rs/serde#1544)). Instead using `content::de` the untagged enums can be replaced by custom buffering. The error messages for `OneOrMany` and `PickFirst` now look like this, including the original failure for each variant. ```text OneOrMany could not deserialize any variant: One: invalid type: map, expected u32 Many: invalid type: map, expected a sequence ``` ```text PickFirst could not deserialize any variant: First: invalid type: string "Abc", expected u32 Second: invalid digit found in string ``` The implementations of `VecSkipError` and `DefaultOnError` are updated too, but should not result in any visible changes. Co-authored-by: Jonas Bushart <[email protected]>
2 parents eb1965a + 73f9e40 commit 7d670c2

File tree

5 files changed

+237
-172
lines changed

5 files changed

+237
-172
lines changed

serde_with/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
* Improve the error message when deserializing `OneOrMany` or `PickFirst` fails.
13+
It now includes the original error message for each of the individual variants.
14+
This is possible by dropping untagged enums as the internal implementations, since they will likely never support this, as these old PRs show [serde#2376](https://github.com/serde-rs/serde/pull/2376) and [serde#1544](https://github.com/serde-rs/serde/pull/1544).
15+
16+
The new errors look like:
17+
18+
```text
19+
OneOrMany could not deserialize any variant:
20+
One: invalid type: map, expected u32
21+
Many: invalid type: map, expected a sequence
22+
```
23+
24+
```text
25+
PickFirst could not deserialize any variant:
26+
First: invalid type: string "Abc", expected u32
27+
Second: invalid digit found in string
28+
```
29+
1030
## [2.3.1] - 2023-03-10
1131
1232
### Fixed

serde_with/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ chrono_0_4 = {package = "chrono", version = "0.4.20", optional = true, default-f
6565
doc-comment = {version = "0.3.3", optional = true}
6666
hex = {version = "0.4.3", optional = true, default-features = false}
6767
indexmap_1 = {package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"]}
68+
# The derive feature is needed for the flattened_maybe macro.
69+
# https://github.com/jonasbb/serde_with/blob/eb1965a74a3be073ecd13ec05f02a01bc1c44309/serde_with/src/flatten_maybe.rs#L67
6870
serde = {version = "1.0.122", default-features = false, features = ["derive"]}
6971
serde_json = {version = "1.0.45", optional = true, default-features = false}
7072
serde_with_macros = {path = "../serde_with_macros", version = "=2.3.1", optional = true}

0 commit comments

Comments
 (0)