Skip to content

Commit 91c356e

Browse files
committed
feat: add more info to validation errors
1 parent 9d6b146 commit 91c356e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- More permissive schema_uri matching to allow future versions of extension schemas ([#1231](https://github.com/stac-utils/pystac/pull/1231))
8+
- Better error messages from jsonschema validation ([#1233](https://github.com/stac-utils/pystac/pull/1233))
89

910
## [v1.8.4] - 2023-09-22
1011

pystac/validation/stac_validator.py

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def _validate_from_uri(
210210
msg += f"against schema at {schema_uri}"
211211

212212
best = jsonschema.exceptions.best_match(errors)
213+
if best:
214+
msg += "\n" + str(best)
213215
raise STACValidationError(msg, source=errors) from best
214216

215217
def validate_core(

tests/test_item.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import pystac
1515
import pystac.serialization.common_properties
16-
from pystac import Asset, Catalog, Collection, Item, Link
16+
from pystac import Asset, Catalog, Collection, Item, Link, STACValidationError
1717
from pystac.utils import (
1818
datetime_to_str,
1919
get_opt,
@@ -630,3 +630,10 @@ def test_non_hierarchical_relative_link() -> None:
630630
assert a.target_in_hierarchy(b)
631631
assert root.target_in_hierarchy(next(b.get_items()))
632632
assert root.target_in_hierarchy(root)
633+
634+
635+
def test_invalid_error_message(item: Item) -> None:
636+
item.extra_fields["collection"] = "can't have a collection"
637+
with pytest.raises(STACValidationError) as error:
638+
item.validate()
639+
assert "can't have a collection" in str(error.value)

0 commit comments

Comments
 (0)