Provide structured validation error in Python bindings #197
Labels
Difficulty: Medium
good first issue
Good for newcomers
help wanted
Extra attention is needed
Priority: High
Type: Enhancement
At the moment, it is not possible to safely define a custom exception class via PyO3 that will expose some Rust struct fields as Python-side instance attributes.
The solution is to add an intermediate Python module that will wrap
validate
, catch the underlying exception, and re-raise it via a different class.I am not sure about attributes - maybe it will be better to follow the same structure as in the
ValidationError
struct - separate class forinstance_path
that can be converted to a string or a vector of strings.This approach implies some overhead, but preliminary tests did not indicate any significant slowdown.
As an extra benefit - it will be possible to specify type annotations for functions created on the python-level, so maybe it worth wrapping
is_valid
as well.The snippet above is almost sufficient. Other things:
raise_on_error
in Python bindings code, so it passes a tuple of needed attributes to the bindings-levelValidationError
;The text was updated successfully, but these errors were encountered: