beatrichartz/csv

Line number is wrong in error message when headers: true

lasseebert opened this issue · 3 comments

Simple example:

iex(4)> CSV.decode!([",", ",,"]) |> Stream.run()
** (CSV.RowLengthError) Row has length 3 - expected length 2 on line 2

iex(4)> CSV.decode!([",", ",,"], headers: true) |> Stream.run()
** (CSV.RowLengthError) Row has length 3 - expected length 2 on line 1

The error message in the first example is correct, since it is the second line that has length 3. In the second example, the error is the same, but because headers: true, it says "line 1".

Is this expected or a bug?

I think this should either be Row has length 3 - expected length 2 on line 2 or Row has length 3 - expected length 2 in row 1 as line refers to the file. Great catch! Want to open a pr?

Yes, I can give it a go on fixing the error message.

I will go for the "on line x" approach (not "on row x"), since the error message is then understandable by an end-user with a CSV-file 👍

Awesome, thanks