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


##########
src/main/java/org/apache/commons/csv/CSVParser.java:
##########
@@ -438,6 +440,44 @@ public CSVParser(final Reader reader, final CSVFormat 
format, final long charact
         this.recordNumber = recordNumber - 1;
     }
 
+    /**
+     * Return the parsed CSV content of currently parsed line up until this 
method is called.

Review Comment:
   If it's just a string I'm not sure it's "parsed". Maybe just "Return the 
text of the current line up until this method is called." 



##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1642,4 +1643,70 @@ private void validateRecordPosition(final String 
lineSeparator) throws IOExcepti
         parser.close();
     }
 
+    @Test
+    public void 
testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1() {
+        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 = null;
+        try {
+            csvParser = csvFormat.parse(stringReader);
+        } catch (IOException e) {
+            fail("Failed to parse the CSV content");

Review Comment:
   I still see it. Do you need to push?



##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1642,4 +1643,70 @@ private void validateRecordPosition(final String 
lineSeparator) throws IOExcepti
         parser.close();
     }
 
+    @Test
+    public void 
testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1() {
+        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 = null;
+        try {
+            csvParser = csvFormat.parse(stringReader);
+        } catch (IOException e) {
+            fail("Failed to parse the CSV content");
+        }
+        final Iterable<CSVRecord> finalRecords = csvParser;
+        Exception exception = assertThrows(UncheckedIOException.class, () -> {
+            for (CSVRecord record : finalRecords) {
+                System.out.println(record.get(0) + " " + record.get(1) + " " + 
record.get(2) + " " + record.get(3)
+                        + " " + record.get(4) + " " + record.get(5) + " " + 
record.get(6) + " " + record.get(7)
+                        + " " + record.get(8) + " " + record.get(9));
+            }
+        });
+        String expectedErrorMessage = "Exception reading next record: 
java.io.IOException: An exception occurred " +
+                "while parsing the CSV content. Issue in line: 2, position: 
94";
+        String actualMessage = exception.getMessage();
+        assertTrue(actualMessage.contains(expectedErrorMessage));
+        assertNotNull(csvParser);

Review Comment:
   csvParser is guaranteed non-null by the time this line is reached



-- 
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