Skip to content

Propagate error message from jsonschema to STACValidationError #901

Closed
@ryanjdillon

Description

@ryanjdillon

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions