DataFixerUpper icon indicating copy to clipboard operation
DataFixerUpper copied to clipboard

Improve Error Messages for EitherCodec and EitherMapCodec

Open alcatrazEscapee opened this issue 4 years ago • 1 comments

Problem

If an error occurs during decoding using an EitherCodec or EitherMapCodec, the error message will only include the message from the second Codec, and will make no mention of the fact this is an Either codec. This can lead to cases of very misleading errors, such as the infamous "Not a JSON Object" error, when in actuality, it was due to an EitherCodec's message only including the second error and not mentioning the fact that an Either is involved.

Solution

EitherCodec and EitherMapCodec were modified to concatenate both error messages, and clearly label them as due to an Either.

Examples

Below are the errors that are reported with no changes to EitherCodec or EitherMapCodec, from the examples listed in EitherErrorReportingTest:

Not a JSON object: 15
Value 15 outside of range [0:10]
No key value in MapLike[{"data":"oops"}]
No key data in MapLike[{"value":15}]
Value 15 outside of range [0:10]
Not a JSON object: "oops"

And here are the same errors, after applying my changes:

Either [Not a JSON object: 15; Value 15 outside of range [0:10]]
Either [Value 15 outside of range [0:10]; No key data in MapLike[{"value":15}]]
Either [No key data in MapLike[{"value":15}]; Value 15 outside of range [0:10]]
Either [Not a JSON object: "oops"; No key value in MapLike[{"data":"oops"}]]
Either [No key value in MapLike[{"data":"oops"}]; Not a JSON object: "oops"]
Either [Value 15 outside of range [0:10]; Not a JSON object: 15]

As you can see, the second set of errors both clearly identify that there was an Either in play here, and also report how neither of the either were able to decode the input.

Both errors are included in the error message, which gives better feedback to the end consumer of these errors and helps identify what was incorrect about their data.

alcatrazEscapee avatar Oct 24 '20 18:10 alcatrazEscapee

CLA assistant check
All CLA requirements met.

ghost avatar Oct 24 '20 18:10 ghost

Closing and reopening to rerun checks.

peterix avatar Oct 26 '22 15:10 peterix

Looks to have been implemented by https://github.com/Mojang/DataFixerUpper/commit/0e553293eb13aa08bac6980943e38fbaee6ebf22, thank you!

alcatrazEscapee avatar Mar 20 '24 14:03 alcatrazEscapee