Skip to content

Commit

Permalink
Merge pull request #688 from NASA-PDS/issue_680
Browse files Browse the repository at this point in the history
More concise error message when possible record_length mismatch
  • Loading branch information
jordanpadams committed Aug 23, 2023
2 parents ec0283d + 450ff49 commit 7c64980
Show file tree
Hide file tree
Showing 5 changed files with 8,725 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
4 changes: 4 additions & 0 deletions src/test/resources/features/validate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Scenario Outline: Execute validate command for tests below.
Examples:
| testName | testDir | messageCount | messageText | problemEnum | resourceDir | reportDir | commandArgs | refOutputValue |

# Validate#680
|"NASA-PDS/validate#680 Success char table correct length" | "github680" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.1.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen96.xml" | "report_github680.1.json" |
|"NASA-PDS/validate#680 Failure char table bad length" | "github680" | 1 | "1 errors expected" | "RECORD_LENGTH_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.2.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen95.xml" | "report_github680.2.json" |

# Validate#684
|"NASA-PDS/validate#684 Success without filesize" | "github684" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github684_1.json -s json --skip-context-validation -t {resourceDir}/github684/example_params_noFileSize.xml" | "report_github684_1.json" |
|"NASA-PDS/validate#684 Success with filesize" | "github684" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github684_2.json -s json --skip-context-validation -t {resourceDir}/github684/example_params_wFileSize.xml" | "report_github684_2.json" |
Expand Down
Loading

0 comments on commit 7c64980

Please sign in to comment.