Skip to content

Commit

Permalink
if not enough data, error out
Browse files Browse the repository at this point in the history
Rather than display 50000+ error messages when the record length is too small, just print one message then continue
  • Loading branch information
Al Niessner authored and Al Niessner committed Aug 22, 2023
1 parent 3405151 commit a0c8d95
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.opencsv.exceptions.CsvValidationException;
import gov.nasa.pds.label.object.FieldDescription;
import gov.nasa.pds.label.object.TableObject;
import gov.nasa.pds.label.object.TableRecord;
import gov.nasa.pds.objectAccess.InvalidTableException;
Expand Down Expand Up @@ -478,6 +479,20 @@ private void validateTableCharacterContent(FieldValueValidator fieldValueValidat
lineNumber, line.length(), line);
if (tableIsFixedLength) {
this.recordLineLength(lineLengthsArray, lineNumbersArray, line, lineNumber + 1);
int minLineLength = 0;
for (FieldDescription field : this.currentTableReader.getFields()) {
if (field.getOffset() + field.getLength() > minLineLength) {
minLineLength = field.getOffset() + field.getLength();
}
}
minLineLength = minLineLength + DelimiterType.getDelimiterType(recordDelimiter).getRecordDelimiter().length();
if (line.length() < minLineLength) {
addTableProblem(ExceptionType.ERROR, ProblemType.RECORD_LENGTH_MISMATCH,
"The fixed line size from label of " + line.length()
+ " bytes is less than the number of bytes defined by the fields " + minLineLength,
dataFile, dataObjectIndex, this.currentTableReader.getCurrentRow());
return;
}
}
} else {
LOG.debug("validateTableCharacter:POSITION_1:lineNumber,line {},[{}]", lineNumber, line);
Expand Down

0 comments on commit a0c8d95

Please sign in to comment.