Skip to content

Commit

Permalink
Merge pull request #224 from kbss-cvut/upd-improve-tabular-logs
Browse files Browse the repository at this point in the history
[Upd] Improve logs when reading input file with tabular data fails
  • Loading branch information
blcham authored Oct 17, 2023
2 parents cf9d9e8 + 2a96df9 commit 54f1c78
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.exception.ResourceNotFoundException;
import cz.cvut.spipes.exception.ResourceNotUniqueException;
import cz.cvut.spipes.exception.SPipesException;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import cz.cvut.spipes.modules.exception.SheetDoesntExistsException;
import cz.cvut.spipes.modules.exception.SheetIsNotSpecifiedException;
Expand Down Expand Up @@ -312,7 +313,7 @@ ExecutionContext executeSelf() {
for (int i = 0; i < header.length; i++) {
// 4.6.8.1
Column column = outputColumns.get(i);
String cellValue = row.get(i);
String cellValue = getValueFromRow(row, i, header.length, rowNumber);
if (cellValue != null) rowStatements.add(createRowResource(cellValue, rowNumber, column));
// 4.6.8.2
r.setDescribes(tableSchema.createAboutUrl(rowNumber));
Expand Down Expand Up @@ -346,6 +347,32 @@ ExecutionContext executeSelf() {
return getExecutionContext(inputModel, outputModel);
}

private String getValueFromRow(List<String> row, int index, int expectedRowLength, int currentRecordNumber) {
try {
return row.get(index);
} catch (IndexOutOfBoundsException e) {
String recordDelimiter = "\n----------\n";
StringBuilder record = new StringBuilder(recordDelimiter);
for (int i = 0; i < row.size(); i++) {
record
.append(i)
.append(":")
.append(row.get(i))
.append(recordDelimiter);
}
LOG.error("Reading input file failed when reading record #{} (may not reflect the line #).\n" +
" It was expected that the current record contains {} values" +
", but {}. element was not retrieved before whole record was processed.\n" +
"The problematic record: {}",
currentRecordNumber,
expectedRowLength,
index+1,
record
);
throw new SPipesException("Reading input file failed.", e);
}
}

private ICsvListReader getCsvListReader(CsvPreference csvPreference) {
if (acceptInvalidQuoting) {
if (getQuote() == '\0') {
Expand Down

0 comments on commit 54f1c78

Please sign in to comment.