Skip to content

Commit dcb1925

Browse files
author
Dai MIKURUBE
committed
Validate InvalidCsvFormatException and InvalidCsvValueException
1 parent 04983a1 commit dcb1925

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

embulk-guess-csv/src/main/java/org/embulk/guess/csv/CsvGuessPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.embulk.config.ConfigSource;
3232
import org.embulk.parser.csv.CsvParserPlugin;
3333
import org.embulk.parser.csv.CsvTokenizer;
34-
import org.embulk.parser.csv.InvalidValueException;
34+
import org.embulk.parser.csv.InvalidCsvQuotationException;
3535
import org.embulk.parser.csv.TooFewColumnsException;
3636
import org.embulk.spi.Buffer;
3737
import org.embulk.spi.BufferAllocator;
@@ -324,7 +324,7 @@ private static List<List<String>> splitLines(
324324
break;
325325
}
326326
}
327-
} catch (final InvalidValueException ex) {
327+
} catch (final InvalidCsvQuotationException ex) {
328328
// TODO warning
329329
tokenizer.skipCurrentLine();
330330
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ private String nextColumn() {
443443
}
444444
pageBuilder.addRecord();
445445

446-
} catch (InvalidFormatException | InvalidValueException | CsvRecordValidateException e) {
446+
} catch (InvalidCsvFormatException | InvalidCsvQuotationException | CsvRecordValidateException e) {
447447
String skippedLine = tokenizer.skipCurrentLine();
448448
long lineNumber = tokenizer.getCurrentLineNumber();
449449
if (stopOnInvalidRecord) {

embulk-parser-csv/src/main/java/org/embulk/parser/csv/CsvTokenizer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public String nextColumn() {
402402
quotedValue.append(this.newline);
403403
this.quotedValueLines.add(this.line);
404404
if (!this.nextLine(false)) {
405-
throw new InvalidValueException("Unexpected end of line during parsing a quoted value");
405+
throw new InvalidCsvQuotationException("Unexpected end of line during parsing a quoted value");
406406
}
407407
valueStartPos = 0;
408408

@@ -438,7 +438,7 @@ public String nextColumn() {
438438
quotedValue.append(this.line.substring(valueStartPos, this.linePos));
439439
this.quotedValueLines.add(this.line);
440440
if (!this.nextLine(false)) {
441-
throw new InvalidValueException("Unexpected end of line during parsing a quoted value");
441+
throw new InvalidCsvQuotationException("Unexpected end of line during parsing a quoted value");
442442
}
443443
valueStartPos = 0;
444444
} else if (this.isQuote(next) || this.isEscape(next)) { // escaped quote
@@ -473,7 +473,7 @@ public String nextColumn() {
473473
// column has trailing spaces and quoted. TODO should this be rejected?
474474

475475
} else {
476-
throw new InvalidValueException(String.format("Unexpected extra character '%c' after a value quoted by '%c'", c, this.quote));
476+
throw new InvalidCsvQuotationException(String.format("Unexpected extra character '%c' after a value quoted by '%c'", c, this.quote));
477477
}
478478
break;
479479

embulk-parser-csv/src/main/java/org/embulk/parser/csv/InvalidCsvFormatException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import org.embulk.spi.DataException;
2020

21-
public class InvalidFormatException extends DataException {
22-
public InvalidFormatException(final String message) {
21+
public class InvalidCsvFormatException extends DataException {
22+
public InvalidCsvFormatException(final String message) {
2323
super(message);
2424
}
2525
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/InvalidCsvQuotationException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import org.embulk.spi.DataException;
2020

21-
public class InvalidValueException extends DataException {
22-
public InvalidValueException(final String message) {
21+
public class InvalidCsvQuotationException extends DataException {
22+
public InvalidCsvQuotationException(final String message) {
2323
super(message);
2424
}
2525
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/QuotedSizeLimitExceededException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.embulk.parser.csv;
1818

19-
public class QuotedSizeLimitExceededException extends InvalidValueException {
19+
public class QuotedSizeLimitExceededException extends InvalidCsvQuotationException {
2020
public QuotedSizeLimitExceededException(final String message) {
2121
super(message);
2222
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/TooFewColumnsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.embulk.parser.csv;
1818

19-
public class TooFewColumnsException extends InvalidFormatException {
19+
public class TooFewColumnsException extends InvalidCsvFormatException {
2020
public TooFewColumnsException(final String message) {
2121
super(message);
2222
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/TooManyColumnsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.embulk.parser.csv;
1818

19-
public class TooManyColumnsException extends InvalidFormatException {
19+
public class TooManyColumnsException extends InvalidCsvFormatException {
2020
public TooManyColumnsException(final String message) {
2121
super(message);
2222
}

embulk-parser-csv/src/test/java/org/embulk/parser/csv/TestCsvTokenizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void throwWithDefaultQuotesInQuotedFields() throws Exception {
300300
parse(builder, "\n", 2, "\"foo\"bar\",\"hoge\"fuga\"");
301301
fail();
302302
} catch (Exception e) {
303-
assertTrue(e instanceof InvalidValueException);
303+
assertTrue(e instanceof InvalidCsvQuotationException);
304304
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
305305
return;
306306
}
@@ -314,7 +314,7 @@ public void throwWithQuotesInQuotedFields_ACCEPT_ONLY_RFC4180_ESCAPED() throws E
314314
parse(builder, "\n", 2, "\"foo\"bar\",\"hoge\"fuga\"");
315315
fail();
316316
} catch (Exception e) {
317-
assertTrue(e instanceof InvalidValueException);
317+
assertTrue(e instanceof InvalidCsvQuotationException);
318318
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
319319
return;
320320
}

0 commit comments

Comments
 (0)