[ 
https://issues.apache.org/jira/browse/CSV-147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17760277#comment-17760277
 ] 

Buddhi De Silva edited comment on CSV-147 at 8/30/23 8:18 AM:
--------------------------------------------------------------

I have looked into this issue and the suggested fix.

I have performed something similar to what [~britter] suggested. This solution 
wrap `lexer.nextToken(this.reusableToken)` and change the exception message.

Now, with this fix, I was able to get following optimized error message.
{code:java}
java.io.IOException: An error occurred while tying to parse the CSV content. 
Error in line: 2, position: 94, last parsed content: 
...rec4,rec5,rec6,rec7,rec8 {code}
Please see the proposed PR: [https://github.com/apache/commons-csv/pull/347] 


was (Author: JIRAUSER301913):
I have looked into this issue and the suggested fix.

I have performed something similar to what [~britter] suggested. This solution 
wrap `lexer.nextToken(this.reusableToken)` and change the exception message.

Now, with this fix, I was able to get following optimized error message.

```

java.io.IOException: An error occurred while tying to parse the CSV content. 
Error in line: 2, position: 94, last parsed content: ...rec4,rec5,rec6,rec7,rec8

```

Please see the proposed PR: [https://github.com/apache/commons-csv/pull/347] 

> Better error handling in CSV, see included code
> -----------------------------------------------
>
>                 Key: CSV-147
>                 URL: https://issues.apache.org/jira/browse/CSV-147
>             Project: Commons CSV
>          Issue Type: Improvement
>          Components: Parser
>    Affects Versions: 1.1
>            Reporter: Steven Peterson
>            Priority: Major
>              Labels: easyfix
>             Fix For: Discussion
>
>         Attachments: csv-exceptionsupport.patch
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> When parsing long files, and there is problem with parsing the data, it would 
> be very useful to know the exact data that is bad when an exception is 
> thrown.  As CSVParser maintains a portion of the current record that was read 
> when an exception is thrown (in the 'record' property), can we make this 
> information public through something like this:
> {code:java}
> public String[] getLastRecordData() {
>   return this.record.toArray(new String[this.record.size()]);
> }
> {code}
> With a method like this, it would be easy to pull in part of the data that 
> was in the faulty record after an exception was thrown, aiding in cleaning up 
> the data.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to