RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
245 stars 63 forks source link

Uncaught NotImplementedError in CLI for ConstraintComponent with missing validator #239

Closed zyzzyxdonta closed 1 month ago

zyzzyxdonta commented 1 month ago

Example shapes:

@prefix ex: <https://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

ex:NoValidatorConstraintComponent a sh:ConstraintComponent ;
    sh:parameter [
        sh:path ex:nothing ;
    ] ;
    # no validator here
    .

ex:NoValidatorNodeShape a sh:NodeShape ;
    sh:targetClass ex:Thing ;
    ex:nothing true .

Example data:

@prefix ex: <https://example.org/> .

ex:1 a ex:Thing .

Output of pyshacl --metashacl -s example-shapes.ttl example-data.ttl:

Validator feature is not implemented:
Traceback (most recent call last):
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/cli.py", line 255, in main
    is_conform, v_graph, v_text = validate(args.data, **validator_kwargs)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/validate.py", line 491, in validate
    conforms, report_graph, report_text = validator.run()
                                          ^^^^^^^^^^^^^^^
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/validate.py", line 313, in run
    _is_conform, _reports = s.validate(executor, g)
                            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/shape.py", line 589, in validate
    validator = a.make_validator_for_shape(self)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/constraints/constraint_component.py", line 438, in make_validator_for_shape
    raise NotImplementedError()
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pape58/.local/bin/pyshacl", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/pape58/.local/pipx/venvs/pyshacl/lib64/python3.12/site-packages/pyshacl/cli.py", line 282, in main
    sys.stderr.write(str(nie.args[0]))
                         ~~~~~~~~^^^
IndexError: tuple index out of range

The same error occurs when a validator is specified but doesn't exist.

ashleysommer commented 1 month ago

Thanks @zyzzyxdonta I've pushed a fix for this into main.

Fixed by https://github.com/RDFLib/pySHACL/commit/3189cfe106981b926dec3950d04d96dda5ec9cda