You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/MetaDataValidator.scala
+14-4Lines changed: 14 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -355,15 +355,23 @@ class RowIterator(parser: CsvParser, progress: Option[ProgressFor], maxCharsPerC
355
355
356
356
privatevarindex=1
357
357
privatevarcurrent= toRow(Try(parser.parseNext()))
358
+
privatevarpotentialHeaderRow:Option[Row] =None
358
359
359
360
@throws(classOf[IOException])
360
361
overridedefnext():Row= {
361
362
valrow= current match {
362
-
caseSuccess(row) => row
363
+
caseSuccess(row) =>
364
+
if(index ==1&& potentialHeaderRow.isEmpty) potentialHeaderRow =Some(row) // this is here in case the old API is used that doesn't call 'skipHeader'
365
+
row
363
366
caseFailure(ex: TextParsingException) if(ex.toString.contains("exceeds the maximum number of characters")) =>
367
+
valcellLocationMsg=
368
+
potentialHeaderRow match {
369
+
caseSome(headerRow) =>s"in the cell located at line: ${ex.getLineIndex}, column: ${headerRow.cells(ex.getColumnIndex).value},"
370
+
caseNone=>s"in column ${ex.getColumnIndex +1} of the header row"
371
+
}
372
+
364
373
valcustomMessage=
365
-
s"The number of characters in the cell located at line: ${ex.getLineIndex +1}, column: ${ex.getColumnIndex +1}, "+
366
-
s"is larger than the maximum number of characters allowed in a cell ($maxCharsPerCell); increase this limit and re-run."
374
+
s"The number of characters $cellLocationMsg is larger than the maximum number of characters allowed in a cell ($maxCharsPerCell); increase this limit and re-run."
367
375
thrownewException(customMessage)
368
376
caseFailure(ex) =>throw ex
369
377
}
@@ -385,7 +393,9 @@ class RowIterator(parser: CsvParser, progress: Option[ProgressFor], maxCharsPerC
Copy file name to clipboardExpand all lines: csv-validator-core/src/test/scala/uk/gov/nationalarchives/csv/validator/api/CsvValidatorMaxCharsPerCellSpec.scala
+10-2Lines changed: 10 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,11 +25,19 @@ class CsvValidatorMaxCharsPerCellSpec extends Specification with TestResources {
List(FailMessage(ValidationError,"java.lang.Exception: The number of characters in the cell located at line: 1, column: 1, is larger than the maximum number of characters allowed in a cell (2); increase this limit and re-run.",None,None))
32
+
List(FailMessage(ValidationError,"java.lang.Exception: The number of characters in column 1 of the header row is larger than the maximum number of characters allowed in a cell (2); increase this limit and re-run.",None,None))
33
+
)
34
+
}
35
+
36
+
"fail if the number of characters in a cell in a non-header row is more than the maxCharsPerCell number and indicate the column name" in {
List(FailMessage(ValidationError,"java.lang.Exception: The number of characters in the cell located at line: 1, column: col2, is larger than the maximum number of characters allowed in a cell (15); increase this limit and re-run.",None,None))
0 commit comments