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

Propagate error message from jsonschema to STACValidationError #901

Closed
ryanjdillon opened this issue Oct 14, 2022 · 2 comments · Fixed by #1233
Closed

Propagate error message from jsonschema to STACValidationError #901

ryanjdillon opened this issue Oct 14, 2022 · 2 comments · Fixed by #1233
Assignees
Milestone

Comments

@ryanjdillon
Copy link

ryanjdillon commented Oct 14, 2022

I ran into some ambiguous validation errors, and the problem would have been a lot more obvious had the originating jsonschema error message been propagated to the STACValidationError.

Perhaps this original error message could be appended to the existing validator error? Update: I now see that jsonschema error outputs can at times be rather large, albeit helpful.
Perhaps some docs on suggested validation practices? Like some handling process shown below to prune the needed diagnosing information.

Example

In a test I am validating a generated item:

item.validate()

I received the following error

> raise pystac.STACValidationError(msg, source=e) from e
E pystac.errors.STACValidationError: Validation failed for Feature with ID a996d0ef-7f8d-4d41-92e2-64518e7c05af against schema at https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json

When I inspected that source error, I saw that

<ValidationError: "'collection' is a required property">

My current solution

try:
    item.validate()
except pystac.errors.STACValidationError as error:                                              
    raise type(error)(f"{str(error)}\n{str(error.source)}", source=error.source)
@ryanjdillon ryanjdillon changed the title Propagate error from jsonschema to STACValidationError Propagate error message from jsonschema to STACValidationError Oct 14, 2022
@gadomski
Copy link
Member

Per python-jsonschema/jsonschema#1050 (comment), once jsonschema 4.18 is released, we might be able to build better error messages. I'm considering this issue blocked until that release.

@gadomski
Copy link
Member

This issue is now unblocked thanks to #1215

@gadomski gadomski added this to the 1.9 milestone Sep 20, 2023
@gadomski gadomski self-assigned this Sep 27, 2023
@gadomski gadomski moved this from Todo to In Progress in STAC Sprint 2023 Sep 27, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in STAC Sprint 2023 Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants