Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

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

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions pystac/validation/stac_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -636,3 +636,10 @@ def test_pathlib() -> None:
# This works, but breaks mypy until we fix
# https://github.com/stac-utils/pystac/issues/1216
Item.from_file(Path(TestCases.get_path("data-files/item/sample-item.json")))


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)