Commit b0a649e
committed
When a serde(untagged) enum can't deser, show all the reasons why
I was writing some code recently that uses `serde(untagged)` for
an enum when deserializing certain JSON schema, but I was unhappy
with the quality of the error messages I was getting, because it
doesn't really tell you why each possibility doesn't work.
I noticed that there is a TODO item in the `serde_derive` proc
macro code that generates this deserialization.
I decided that trying to improve the error messages upstream in
serde-derive is easier than trying to change how I'm using serde,
so I took a stab at implementing this TODO, and updating the tests
that test error messages, and writing some more tests.
I have tried to follow the patterns and conventions that I have
seen elsewhere in the serde-derive source code, and I think that
the code gen is good in that it uses `format_args!` like other
parts of serde error handling and avoids making a new dynamic memory
allocation. When untagged deserialization fails, the errors are
collected on the stack rather than in a new dynamically-sized
container.
Let me know if you think this is a good direction, I'm happy to
iterate if this patch is interesting to you. Thanks for building
serde, it's great.1 parent f85c4f2 commit b0a649e
File tree
3 files changed
+94
-8
lines changed- serde_derive/src
- test_suite/tests
3 files changed
+94
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1686 | 1686 | | |
1687 | 1687 | | |
1688 | 1688 | | |
1689 | | - | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
1690 | 1707 | | |
1691 | 1708 | | |
1692 | 1709 | | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
1696 | 1718 | | |
1697 | 1719 | | |
1698 | | - | |
| 1720 | + | |
1699 | 1721 | | |
1700 | 1722 | | |
1701 | 1723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2776 | 2776 | | |
2777 | 2777 | | |
2778 | 2778 | | |
2779 | | - | |
| 2779 | + | |
| 2780 | + | |
2780 | 2781 | | |
2781 | 2782 | | |
2782 | 2783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
665 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
666 | 672 | | |
667 | 673 | | |
668 | 674 | | |
| |||
673 | 679 | | |
674 | 680 | | |
675 | 681 | | |
676 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
677 | 689 | | |
678 | 690 | | |
679 | 691 | | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
680 | 743 | | |
681 | 744 | | |
682 | 745 | | |
| |||
0 commit comments