Skip to content

Commit

Permalink
GH-4867 log exceptions as warnings during parsing and validation of S…
Browse files Browse the repository at this point in the history
…HACL shapes (#4868)
  • Loading branch information
hmottestad authored Jan 13, 2024
2 parents d8bdc75 + 1ac18bf commit fb2cab4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ public ValidationResultIterator performValidation() {
sail.getEffectiveValidationResultsLimitPerConstraint());
return validationResults;
} catch (Exception e) {
logger.warn("Error validating SHACL Shape {}", shape.getId(), e);
throw new SailException("Error validating SHACL Shape " + shape.getId() + "\n" + shape, e);
} finally {
handlePostLogging(before, validationResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public static ValidationReport validate(Sail dataRepo, Sail shapesRepo) {

}
shapesConnection.commit();
} catch (Exception e) {
logger.warn("Failed to read shapes", e);
throw e;
}

try (SailConnection dataRepoConnection = dataRepo.getConnection()) {
Expand All @@ -95,6 +98,9 @@ public static ValidationReport validate(Sail dataRepo, Sail shapesRepo) {
return performValidation(shapes, new ConnectionsGroup(verySimpleRdfsBackwardsChainingConnection, null,
null, null, new Stats(), () -> reasoner,
new ShaclSailConnection.Settings(true, true, true, IsolationLevels.NONE), true));
} catch (Exception e) {
logger.warn("Failed to validate shapes", e);
throw e;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public ValidationResultIterator performValidation() {
validationResults = new ValidationResultIterator(iterator, effectiveValidationResultsLimitPerConstraint);
return validationResults;
} catch (Exception e) {
logger.warn("Error validating SHACL Shape {}", shape.getId(), e);
throw new SailException("Error validating SHACL Shape " + shape.getId() + "\n" + shape, e);
} finally {
handlePostLogging(before, validationResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ public PlanNode generatePlans(ConnectionsGroup connectionsGroup, ValidationSetti
}

} else {
throw new ShaclUnsupportedException("Unkown validation approach: " + validationApproach);
throw new ShaclUnsupportedException("Unknown validation approach: " + validationApproach);
}
} catch (RuntimeException e) {
logger.warn("Error processing SHACL Shape {}", id, e);
throw new SailException("Error processing SHACL Shape " + id + "\n" + this, e);
}

Expand Down Expand Up @@ -707,6 +708,7 @@ public static List<ContextWithShape> getShapesInContext(ShapeSource shapeSource,
try {
return new ShaclProperties(r, shapeSourceWithContext);
} catch (Exception e) {
logger.warn("Error parsing shape {}", r, e);
throw new ShaclShapeParsingException(e, r);
}
})
Expand All @@ -719,6 +721,7 @@ public static List<ContextWithShape> getShapesInContext(ShapeSource shapeSource,
}
throw new ShaclShapeParsingException("Unknown shape type", p.getId());
} catch (Exception e) {
logger.warn("Error parsing shape {}", p.getId(), e);
if (e instanceof ShaclShapeParsingException) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.WriterConfig;
import org.eclipse.rdf4j.rio.helpers.BasicWriterSettings;
import org.eclipse.rdf4j.sail.shacl.ShaclSailConnection;
import org.eclipse.rdf4j.sail.shacl.results.ValidationReport;
import org.eclipse.rdf4j.sail.shacl.results.ValidationResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A ValidationReport that will defer calculating any ValidationResults until the user asks for them
*/
@InternalUseOnly
public class LazyValidationReport extends ValidationReport {

private static final Logger logger = LoggerFactory.getLogger(LazyValidationReport.class);

private List<ValidationResultIterator> validationResultIterators;
private final long limit;

Expand All @@ -55,44 +60,55 @@ public LazyValidationReport(List<ValidationResultIterator> validationResultItera
}

private void evaluateLazyAspect() {
if (validationResultIterators != null) {
long counter = 0;
for (ValidationResultIterator validationResultIterator : validationResultIterators) {
while (validationResultIterator.hasNext()) {
if (limit >= 0 && counter >= limit) {
truncated = true;
break;
try {
if (validationResultIterators != null) {
long counter = 0;
for (ValidationResultIterator validationResultIterator : validationResultIterators) {
while (validationResultIterator.hasNext()) {
if (limit >= 0 && counter >= limit) {
truncated = true;
break;
}
counter++;

validationResult.add(validationResultIterator.next());
}
counter++;

validationResult.add(validationResultIterator.next());
this.conforms = conforms && validationResultIterator.conforms();
this.truncated = truncated || validationResultIterator.isTruncated();
}

this.conforms = conforms && validationResultIterator.conforms();
this.truncated = truncated || validationResultIterator.isTruncated();
}

validationResultIterators = null;
validationResultIterators = null;

}
} catch (Exception e) {
logger.warn("Error evaluating lazy validation report", e);
throw e;
}

}

public Model asModel(Model model) {
evaluateLazyAspect();
try {
evaluateLazyAspect();

model.add(getId(), SHACL.CONFORMS, literal(conforms));
model.add(getId(), RDF.TYPE, SHACL.VALIDATION_REPORT);
model.add(getId(), RDF4J.TRUNCATED, BooleanLiteral.valueOf(truncated));

model.add(getId(), SHACL.CONFORMS, literal(conforms));
model.add(getId(), RDF.TYPE, SHACL.VALIDATION_REPORT);
model.add(getId(), RDF4J.TRUNCATED, BooleanLiteral.valueOf(truncated));
HashSet<Resource> rdfListDedupe = new HashSet<>();

HashSet<Resource> rdfListDedupe = new HashSet<>();
for (ValidationResult result : validationResult) {
model.add(getId(), SHACL.RESULT, result.getId());
result.asModel(model, rdfListDedupe);
}

for (ValidationResult result : validationResult) {
model.add(getId(), SHACL.RESULT, result.getId());
result.asModel(model, rdfListDedupe);
return model;
} catch (Exception e) {
logger.warn("Error converting validation report to model", e);
throw e;
}

return model;
}

public Model asModel() {
Expand Down

0 comments on commit fb2cab4

Please sign in to comment.