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

New sum codec does not report accurate errors #66

Open
wclr opened this issue Dec 29, 2024 · 1 comment · May be fixed by #68
Open

New sum codec does not report accurate errors #66

wclr opened this issue Dec 29, 2024 · 1 comment · May be fixed by #68

Comments

@wclr
Copy link

wclr commented Dec 29, 2024

Brand new sum codecs made by @m-bock make writing sum type codecs a breeze. But there is a problem with decoding error reports that in most cases happen to be are irrelevant.

For example, for this type

data Sample
  = Foo
  | Bar Int
  | Baz Boolean String Int

When parsing (wrong value type):

        $ Str.joinWith "\n"
            [ "{"
            , "  \"tag\": \"Bar\","
            , "  \"values\": \"42\""
            , "}"
            ]

the error reported is: (Named "Sample" (TypeMismatch "Expecting tag Baz, got Bar")). However, one would expect to see something like this: (Named "Sample" (Named "case Bar" (TypeMismatch "Int")))

This is because it currently propagates decoding errors for all cases (without respect to the actual tag value) and reports the error for the last case.

To solve this I refactored the code a bit and added tests for error reporting, going to make a PR.

@wclr wclr linked a pull request Dec 29, 2024 that will close this issue
@m-bock
Copy link
Contributor

m-bock commented Jan 10, 2025

@wclr Sorry for the late reply!
Thanks for reporting, this totally makes sense. I'll have a closer look into your PR!

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

Successfully merging a pull request may close this issue.

3 participants