-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/csv: getting a line number of current record when using csv.Reader #26679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is there any issue using a counter variable to keep track of the no. of lines parsed ? |
@agnivade Probably, since a single record can span multiple lines. E.g. the 3rd record could be from line 7 to 20 in the source. The Reader only tracks the current line not the line where a record started. We could add a method that returns the current line number, but to get the line where the last record started we would need to change the Reader to remember the line. |
/cc @dsnet |
What's wrong with the current information provided: type ParseError struct {
StartLine int // Line where the record starts
Line int // Line where the error occurred
Column int // Column (rune index) where the error occurred
Err error // The actual error
} Isn't |
@dsnet No, I ask for a method to get |
Ah, I see. This seems to be a relatively niche feature, and I'm not sure if the expansion of API is worth it. Something along the lines of what @agnivade suggested should work. The issue of multi-line records can be resolved by sampling the current line before each call to If we changed the internal implementation of |
@dsnet - It is a bit unclear on what is to be done here. Are you suggesting we should check the reader and avoid the re-wrap ? |
ping @dsnet . |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.10.3
Does this issue reproduce with the latest release?
1.10.3 is the latest
What did you do?
I have used csv.Reader to parse a CSV file and I wanted to report an error to user in case some record contained invalid data. I also wanted to include a line number of invalid record in an error message.
What did you expect to see?
some method that would return a line number where current record starts
What did you see instead?
There is no way to get a line number of current record.
The text was updated successfully, but these errors were encountered: