TopQuadrant / shacl

SHACL API in Java based on Apache Jena
Apache License 2.0
217 stars 61 forks source link

Feature request: more helpful error message if SPARQL parsing fails #94

Closed fkleedorfer closed 2 years ago

fkleedorfer commented 4 years ago

I am currently developing some SHACL SPARQL Rules, and debugging is a bit of a hassle because the error message generated by the Jena SPARQL parser is not enriched with information about which rule it is that can't be parsed. E.g.


Exception in thread "main" org.apache.jena.query.QueryParseException: Encountered " <NIL> "() "" at line 2, column 28.
Was expecting one of:
    <IRIref> ...
    <PNAME_NS> ...
    <PNAME_LN> ...
    "a" ...
    "distinct" ...
    "multi" ...
    "shortest" ...
    "(" ...
    "!" ...
    "^" ...

        at org.apache.jena.sparql.lang.ParserARQ.perform(ParserARQ.java:100)
        at org.apache.jena.sparql.lang.ParserARQ.parse$(ParserARQ.java:52)
        at org.apache.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:34)
        at org.apache.jena.query.QueryFactory.parse(QueryFactory.java:147)
        at org.topbraid.jenax.util.ARQFactory.doCreateQuery(ARQFactory.java:207)
        at org.topbraid.jenax.util.ARQFactory.createQuery(ARQFactory.java:237)
        at org.topbraid.shacl.arq.SHACLPaths.getJenaPath(SHACLPaths.java:255)
        at org.topbraid.shacl.engine.Shape.<init>(Shape.java:90)
        at org.topbraid.shacl.engine.ShapesGraph.lambda$getShape$1(ShapesGraph.java:147)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
        at org.topbraid.shacl.engine.ShapesGraph.getShape(ShapesGraph.java:147)
        at org.topbraid.shacl.validation.ValidationEngine.nodesConformToShape(ValidationEngine.java:459)
        at org.topbraid.shacl.rules.RuleEngine.nodeConformsToAllShapes(RuleEngine.java:278)
        at org.topbraid.shacl.rules.RuleEngine.executeShape(RuleEngine.java:176)
        at org.topbraid.shacl.rules.RuleEngine.executeShapes(RuleEngine.java:133)
        at org.topbraid.shacl.rules.RuleEngine.executeAll(RuleEngine.java:93)
        at org.topbraid.shacl.rules.RuleUtil.executeRulesHelper(RuleUtil.java:124)
        at org.topbraid.shacl.rules.RuleUtil.executeRules(RuleUtil.java:63)
        at org.topbraid.shacl.tools.Infer.run(Infer.java:54)
        at org.topbraid.shacl.tools.Infer.main(Infer.java:44)

I understand it may not be easy to provide meaningful information as the rule shape will be a blank node, but if there is something straightforward you can do to help narrow it down, it will be appreciated!

Cheers!

EDIT: The problem, of course, is that I touched multiple SPARQL Rules since the last run and now I don't know which one it is that cannot be parsed.

fkleedorfer commented 4 years ago

Turns out, the problem wasn't in a SPARQL query I changed but in a sh:path expression I also changed. Should have guessed that, but still - shape information in the error message would have helped spot the problem.