dashbitco / nimble_csv

A simple and fast CSV parsing and dumping library for Elixir
https://hexdocs.pm/nimble_csv
767 stars 51 forks source link

Error handling guidance #78

Closed tfwright closed 10 months ago

tfwright commented 10 months ago

Currently when parsing invalid CSV a ParseError is raised. This behavior isn't documented in function docs/type specs and would seem to violate the widespread convention of naming functions that can raise with a !.

I would propose to add some documentation around that (and possibly fix the type spec?)

As part of that it would be nice to offer some guidance on how to approach parsing CSV that may be invalid. Is catching the error the best approach?

josevalim commented 10 months ago

Unfortunately, at the moment, raising is the best way to go. That's because the library was designed to work with streaming and, when streaming, it is tricky to error in the middle of streaming without raising (it is possible, just trickier) and changing it now would be backwards incompatible as you mentioned.