BrianHicks / elm-csv

Decode CSV in the most boring way possible.

Home Page:https://package.elm-lang.org/packages/BrianHicks/elm-csv/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`map2`, `map3` and friends don't preserve all error messages

gampleman opened this issue · comments

For instance:

decoder =
    Decode.map3 (\a b c -> ( a, b, c ))
        (Decode.field "bar" Decode.int)
        (Decode.field "foo" Decode.int)
        (Decode.column 3 Decode.int)


contents =
    """bar
1
2
d
d
5
"""

Decode.decodeCsv Decode.FieldNamesFromFirstRow decoder contents

You would expect that for rows 1,2, and 5 you would get 2 errors (foo not provided, column 3 not found) and 3 errors for rows 3 and 4, but instead you just get 1 error for each row.

This is because they are implemented as Result.map2, Result.map3 etc, which only take the first encountered error, rather than aggregating them as a list.

I was looking at doing a fix for this, but I'm somewhat confused. The decoding error is { row : Int, column: Column, problems: List Problem }, but I can't quite work out when is it possible to have any other number than exactly one problem?

I think we'd need to change the type to look more like List { row : Int, column: Column, problem: Problem } to support this.