You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/09/13 13:00:00 UTC

[commons-csv] branch master updated: changing the exception message to be more meaningful

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new eb95e6df changing the exception message to be more meaningful
     new c2cf3057 Merge pull request #352 from gbidsilva/CSV-310
eb95e6df is described below

commit eb95e6dff7a2eab9f0b52f9f5cac8850f596f8c3
Author: gbidsilva <gb...@gmail.com>
AuthorDate: Wed Sep 6 18:42:13 2023 +0530

    changing the exception message to be more meaningful
---
 src/main/java/org/apache/commons/csv/CSVFormat.java     |  2 +-
 src/test/java/org/apache/commons/csv/CSVFormatTest.java | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 2f7e6b9f..d6218213 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -2449,7 +2449,7 @@ public final class CSVFormat implements Serializable {
         }
 
         if (escapeCharacter == null && quoteMode == QuoteMode.NONE) {
-            throw new IllegalArgumentException("No quotes mode set but no escape character is set");
+            throw new IllegalArgumentException("Quote mode set to NONE but no escape character is set");
         }
 
         // Validate headers
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 4fa96196..f683e62d 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -1477,4 +1477,17 @@ public class CSVFormatTest {
         final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
         assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
     }
+
+    @Test
+    public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
+        Exception exception = assertThrows(IllegalArgumentException.class, () -> {
+            CSVFormat.DEFAULT.builder()
+                    .setHeader("Col1", "Col2", "Col3", "Col4")
+                    .setQuoteMode(QuoteMode.NONE)
+                    .build();
+        });
+        String actualMessage = exception.getMessage();
+        String expectedMessage = "Quote mode set to NONE but no escape character is set";
+        assertEquals(expectedMessage, actualMessage);
+    }
 }