Skip to content

Commit fb2cab4

Browse files
authored
GH-4867 log exceptions as warnings during parsing and validation of SHACL shapes (#4868)
2 parents d8bdc75 + 1ac18bf commit fb2cab4

5 files changed

Lines changed: 51 additions & 24 deletions

File tree

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclSailConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ public ValidationResultIterator performValidation() {
11451145
sail.getEffectiveValidationResultsLimitPerConstraint());
11461146
return validationResults;
11471147
} catch (Exception e) {
1148+
logger.warn("Error validating SHACL Shape {}", shape.getId(), e);
11481149
throw new SailException("Error validating SHACL Shape " + shape.getId() + "\n" + shape, e);
11491150
} finally {
11501151
handlePostLogging(before, validationResults);

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclValidator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public static ValidationReport validate(Sail dataRepo, Sail shapesRepo) {
7777

7878
}
7979
shapesConnection.commit();
80+
} catch (Exception e) {
81+
logger.warn("Failed to read shapes", e);
82+
throw e;
8083
}
8184

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

100106
}

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShapeValidationContainer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public ValidationResultIterator performValidation() {
7777
validationResults = new ValidationResultIterator(iterator, effectiveValidationResultsLimitPerConstraint);
7878
return validationResults;
7979
} catch (Exception e) {
80+
logger.warn("Error validating SHACL Shape {}", shape.getId(), e);
8081
throw new SailException("Error validating SHACL Shape " + shape.getId() + "\n" + shape, e);
8182
} finally {
8283
handlePostLogging(before, validationResults);

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/Shape.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,10 @@ public PlanNode generatePlans(ConnectionsGroup connectionsGroup, ValidationSetti
448448
}
449449

450450
} else {
451-
throw new ShaclUnsupportedException("Unkown validation approach: " + validationApproach);
451+
throw new ShaclUnsupportedException("Unknown validation approach: " + validationApproach);
452452
}
453453
} catch (RuntimeException e) {
454+
logger.warn("Error processing SHACL Shape {}", id, e);
454455
throw new SailException("Error processing SHACL Shape " + id + "\n" + this, e);
455456
}
456457

@@ -707,6 +708,7 @@ public static List<ContextWithShape> getShapesInContext(ShapeSource shapeSource,
707708
try {
708709
return new ShaclProperties(r, shapeSourceWithContext);
709710
} catch (Exception e) {
711+
logger.warn("Error parsing shape {}", r, e);
710712
throw new ShaclShapeParsingException(e, r);
711713
}
712714
})
@@ -719,6 +721,7 @@ public static List<ContextWithShape> getShapesInContext(ShapeSource shapeSource,
719721
}
720722
throw new ShaclShapeParsingException("Unknown shape type", p.getId());
721723
} catch (Exception e) {
724+
logger.warn("Error parsing shape {}", p.getId(), e);
722725
if (e instanceof ShaclShapeParsingException) {
723726
throw e;
724727
}

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/results/lazy/LazyValidationReport.java

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@
3535
import org.eclipse.rdf4j.rio.Rio;
3636
import org.eclipse.rdf4j.rio.WriterConfig;
3737
import org.eclipse.rdf4j.rio.helpers.BasicWriterSettings;
38+
import org.eclipse.rdf4j.sail.shacl.ShaclSailConnection;
3839
import org.eclipse.rdf4j.sail.shacl.results.ValidationReport;
3940
import org.eclipse.rdf4j.sail.shacl.results.ValidationResult;
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
4043

4144
/**
4245
* A ValidationReport that will defer calculating any ValidationResults until the user asks for them
4346
*/
4447
@InternalUseOnly
4548
public class LazyValidationReport extends ValidationReport {
4649

50+
private static final Logger logger = LoggerFactory.getLogger(LazyValidationReport.class);
51+
4752
private List<ValidationResultIterator> validationResultIterators;
4853
private final long limit;
4954

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

5762
private void evaluateLazyAspect() {
58-
if (validationResultIterators != null) {
59-
long counter = 0;
60-
for (ValidationResultIterator validationResultIterator : validationResultIterators) {
61-
while (validationResultIterator.hasNext()) {
62-
if (limit >= 0 && counter >= limit) {
63-
truncated = true;
64-
break;
63+
try {
64+
if (validationResultIterators != null) {
65+
long counter = 0;
66+
for (ValidationResultIterator validationResultIterator : validationResultIterators) {
67+
while (validationResultIterator.hasNext()) {
68+
if (limit >= 0 && counter >= limit) {
69+
truncated = true;
70+
break;
71+
}
72+
counter++;
73+
74+
validationResult.add(validationResultIterator.next());
6575
}
66-
counter++;
6776

68-
validationResult.add(validationResultIterator.next());
77+
this.conforms = conforms && validationResultIterator.conforms();
78+
this.truncated = truncated || validationResultIterator.isTruncated();
6979
}
7080

71-
this.conforms = conforms && validationResultIterator.conforms();
72-
this.truncated = truncated || validationResultIterator.isTruncated();
73-
}
74-
75-
validationResultIterators = null;
81+
validationResultIterators = null;
7682

83+
}
84+
} catch (Exception e) {
85+
logger.warn("Error evaluating lazy validation report", e);
86+
throw e;
7787
}
7888

7989
}
8090

8191
public Model asModel(Model model) {
82-
evaluateLazyAspect();
92+
try {
93+
evaluateLazyAspect();
94+
95+
model.add(getId(), SHACL.CONFORMS, literal(conforms));
96+
model.add(getId(), RDF.TYPE, SHACL.VALIDATION_REPORT);
97+
model.add(getId(), RDF4J.TRUNCATED, BooleanLiteral.valueOf(truncated));
8398

84-
model.add(getId(), SHACL.CONFORMS, literal(conforms));
85-
model.add(getId(), RDF.TYPE, SHACL.VALIDATION_REPORT);
86-
model.add(getId(), RDF4J.TRUNCATED, BooleanLiteral.valueOf(truncated));
99+
HashSet<Resource> rdfListDedupe = new HashSet<>();
87100

88-
HashSet<Resource> rdfListDedupe = new HashSet<>();
101+
for (ValidationResult result : validationResult) {
102+
model.add(getId(), SHACL.RESULT, result.getId());
103+
result.asModel(model, rdfListDedupe);
104+
}
89105

90-
for (ValidationResult result : validationResult) {
91-
model.add(getId(), SHACL.RESULT, result.getId());
92-
result.asModel(model, rdfListDedupe);
106+
return model;
107+
} catch (Exception e) {
108+
logger.warn("Error converting validation report to model", e);
109+
throw e;
93110
}
94111

95-
return model;
96112
}
97113

98114
public Model asModel() {

0 commit comments

Comments
 (0)