Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More concise error message when possible record_length mismatch #688

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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