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

Hide stacktrace for unexpected errors included in the validation report #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

costas80
Copy link

When an exception is raised during validation for specific rules, the current implementation includes as part of the reported violation the full stack trace of the error. This results in unnecessarily long reported errors, which also expose implementation details to the client/user.

This PR makes a small adaptation to only include the message of the exception (without the stack trace), which should contain whatever information is meaningful for the validation report. In practice, before this update an exception-related violation in the report would be reported as:

  sh:result    [ rdf:type                      dash:FailureResult;
                 sh:focusNode                  bsh:DeprecationRuleForInstances;
                 sh:resultMessage              "Failed to create validator: org.topbraid.shacl.validation.SHACLException: Invalid SPARQL constraint (Line 1, column 28: Unresolved prefixed name: rdf:type):\nSELECT $this WHERE { $this rdf:type/owl:deprecated true }\r\n\tat org.topbraid.shacl.validation.sparql.AbstractSPARQLExecutor.<init>(AbstractSPARQLExecutor.java:75)\r\n\tat org.topbraid.shacl.validation.sparql.SPARQLConstraintExecutor.<init>(SPARQLConstraintExecutor.java:53)\r\n\tat org.topbraid.shacl.validation.ConstraintExecutors.lambda$new$2(ConstraintExecutors.java:54)\r\n\tat org.topbraid.shacl.validation.ConstraintExecutors.getExecutor(ConstraintExecutors.java:77)\r\n\tat org.topbraid.shacl.engine.Constraint.getExecutor(Constraint.java:105)\r\n\tat org.topbraid.shacl.validation.ValidationEngine.validateNodesAgainstConstraint(ValidationEngine.java:611)\r\n\tat org.topbraid.shacl.validation.ValidationEngine.validateShapes(ValidationEngine.java:582)\r\n\tat org.topbraid.shacl.validation.ValidationEngine.validateAll(ValidationEngine.java:482)\r\n\tat org.topbraid.shacl.validation.ValidationUtil.validateModel(ValidationUtil.java:123)\r\n\tat org.topbraid.shacl.validation.ValidationUtil.validateModel(ValidationUtil.java:104)\r\n\tat org.topbraid.shacl.tools.Validate.run(Validate.java:60)\r\n\tat org.topbraid.shacl.tools.Validate.main(Validate.java:48)\r\n";
                 sh:resultSeverity             sh:Warning;
                 sh:sourceConstraintComponent  sh:SPARQLConstraintComponent;
                 sh:sourceShape                bsh:DeprecationRuleForInstances
               ];

Whereas with this update it is reported as:

  sh:result    [ rdf:type                      dash:FailureResult;
                 sh:focusNode                  bsh:DeprecationRuleForInstances;
                 sh:resultMessage              "Failed to create validator: Invalid SPARQL constraint (Line 1, column 28: Unresolved prefixed name: rdf:type):\nSELECT $this WHERE { $this rdf:type/owl:deprecated true }";
                 sh:resultSeverity             sh:Warning;
                 sh:sourceConstraintComponent  sh:SPARQLConstraintComponent;
                 sh:sourceShape                bsh:DeprecationRuleForInstances
               ];

Would it be possible to merge this and publish a patch release? Thanks!

@ashleycaselli
Copy link
Collaborator

@costas80 thanks for the contribution! We will review it and include it in the next release.

Copy link
Collaborator

@ashleycaselli ashleycaselli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the code consistent can you please use a method provided by the ExceptionUtil class (e.g. getDeepMessage()) to print the error message?

@costas80
Copy link
Author

Change done @ashleycaselli. Can you recheck please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants