csv-conduit
csv-conduit copied to clipboard
Named CSV instance eats errors
I notice that the instance for CSV eats errors on parse. It first parses rows into NamedRecord
and then parses to an Either String a
, discards the error message and skips the row. I found this surprising as default behavior and it does not appear to be documented. In my case, If you parse a CSV file with some invalid rows, it simply skips them and returns a successful result with the rows that worked. If you have a missing column, it parses successfully and returns that there were no rows. The MonadThrow requirement for IntoCSV seems to be unused.
I could see a few ways forward:
- This is undesirable default behavior and the Named instance will throw a new exception that wraps the String error message. We could create a newtype like
Named
calledNamedSkipErrors
or something more pithy that uses this current implementation of eating errors. - This is valid default behavior and we don't want to break existing installs, so we create a
NamedThrowErrors
or something more pithy that throws on invalid rows. - This could be added to either of the above as
newtype NamedOrError a = NamedOrError (Either String a)
which also never throws but captures per-row errors and lifts them into the types so they can be dealt with.
Because these are all solved by newtypes, this is something I can do myself in userland code without changing the library in the mean time.