mayur mohan created CAMEL-24546:
-----------------------------------

             Summary: camel-csv: wrap CSV parse IOException with diagnostic 
message in CsvUnmarshaller
                 Key: CAMEL-24546
                 URL: https://issues.apache.org/jira/browse/CAMEL-24546
             Project: Camel
          Issue Type: Improvement
            Reporter: mayur mohan


When camel-csv unmarshal encounters malformed CSV (e.g. a quoted field with 
extra characters after the closing quote), Apache Commons CSV throws a raw 
IOException with a technical message that is hard to diagnose:

  java.io.IOException: (line 1) invalid char between encapsulated token and 
delimiter
    at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:281)
    at org.apache.commons.csv.CSVParser.createHeaders(CSVParser.java:483)
    at 
org.apache.camel.dataformat.csv.CsvUnmarshaller$BulkCsvUnmarshaller.unmarshal(CsvUnmarshaller.java:105)
    at 
org.apache.camel.dataformat.csv.CsvDataFormat.unmarshal(CsvDataFormat.java:95)

The fix wraps the IOException in CsvUnmarshaller (both BulkCsvUnmarshaller and 
StreamCsvUnmarshaller) with a diagnostic message identifying the root cause and 
guiding operators to check their delimiter and quote character configuration.

Error message after fix:
  CSV parse failed: (line 1) invalid char between encapsulated token and 
delimiter. A quoted field has extra characters after the closing quote and 
before the delimiter (example: "abc"x,def). Check delimiter, quote character, 
and escaped quotes ("").

This is a cosmetic/diagnostic-only change. No behavior, API, or data format 
change.



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

Reply via email to