Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a pretty decoder that removes Aeson portion of decoding error #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AugmenTab
Copy link
Contributor

This splits the error message produced by fromValue into two: the Aeson and Fleece error message combined (the original behavior) and just the Fleece error message (that produced by the schema and the Decoder functions). decodePretty, as a result, produces a slightly easier to understand error message that is more suitable for displaying to users. Ideally, we would be able to remove the type from the error messages produced by the Decoder functions as well, but for now, this isn't changing that since it would alter the current tests' expected results.

This splits the error message produced by `fromValue` into two:
the Aeson and Fleece error message combined (the original behavior)
and just the Fleece error message (that produced by the schema and
the `Decoder` functions). `decodePretty`, as a result, produces a
slightly easier to understand error message that is more suitable
for displaying to users. Ideally, we would be able to remove the
type from the error messages produced by the `Decoder` functions as
well, but for now, this isn't changing that since it would alter
the current tests' expected results.
@AugmenTab AugmenTab requested a review from qxjit January 2, 2024 18:59

decodePretty :: Decoder a -> LBS.ByteString -> Either String a
decodePretty decoder =
mapLeft snd . fromValue decoder <=< Aeson.eitherDecode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather that offer a separate decodePretty function it would be better to make the decode function return a new error type other than String that the caller could then decide how to format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants