diff --git a/pystac/validation/stac_validator.py b/pystac/validation/stac_validator.py index 35d6d826f..1117e9fd3 100644 --- a/pystac/validation/stac_validator.py +++ b/pystac/validation/stac_validator.py @@ -210,6 +210,8 @@ def _validate_from_uri( msg += f"against schema at {schema_uri}" best = jsonschema.exceptions.best_match(errors) + if best: + msg += "\n" + str(best) raise STACValidationError(msg, source=errors) from best def validate_core( diff --git a/tests/test_item.py b/tests/test_item.py index c3274d003..83e4ad529 100644 --- a/tests/test_item.py +++ b/tests/test_item.py @@ -13,7 +13,7 @@ import pystac import pystac.serialization.common_properties -from pystac import Asset, Catalog, Collection, Item, Link +from pystac import Asset, Catalog, Collection, Item, Link, STACValidationError from pystac.utils import ( datetime_to_str, get_opt, @@ -630,3 +630,10 @@ def test_non_hierarchical_relative_link() -> None: assert a.target_in_hierarchy(b) assert root.target_in_hierarchy(next(b.get_items())) assert root.target_in_hierarchy(root) + + +def test_invalid_error_message(item: Item) -> None: + item.extra_fields["collection"] = "can't have a collection" + with pytest.raises(STACValidationError) as error: + item.validate() + assert "can't have a collection" in str(error.value)