Skip to content

New sum codec does not report accurate errors #66

Open
@wclr

Description

@wclr

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions