elharo commented on code in PR #347:
URL: https://github.com/apache/commons-csv/pull/347#discussion_r1316570099


##########
src/main/java/org/apache/commons/csv/Lexer.java:
##########
@@ -367,8 +367,7 @@ private Token parseEncapsulatedToken(final Token token) 
throws IOException {
                         }
                         if (!Character.isWhitespace((char)c)) {
                             // error invalid char between token and next 
delimiter
-                            throw new IOException("(line " + 
getCurrentLineNumber() +
-                                    ") invalid char between encapsulated token 
and delimiter");
+                            throw new IOException("Invalid char between 
encapsulated token and delimiter at line: " + getCurrentLineNumber() + ", 
position: " + getCharacterPosition());

Review Comment:
   This probably shouldn't be an IOException but that issue is not new with 
this PR



##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1642,4 +1642,26 @@ private void validateRecordPosition(final String 
lineSeparator) throws IOExcepti
         parser.close();
     }
 
+    @Test
+    public void testFaultyCSVShouldThrowExceptionWithLineAndPosition() throws 
IOException {
+        String csvContent = 
"col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
+                "rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
+
+        StringReader stringReader = new StringReader(csvContent);
+        CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+                .setHeader()
+                .setSkipHeaderRecord(true)
+                .build();
+
+        CSVParser csvParser = csvFormat.parse(stringReader);
+        Exception exception = assertThrows(UncheckedIOException.class, () -> {

Review Comment:
   UncheckedIOException is not right either, but again not new in this PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to