Skip to content

Commit c53a8aa

Browse files
authored
Merge pull request #213 from stac-utils/val_errors
Make Validation errors clearer
2 parents bb1cbd6 + c31e3bd commit c53a8aa

File tree

8 files changed

+20
-14
lines changed

8 files changed

+20
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
66

77
## Unreleased
88

9+
### Changed
10+
11+
- Changed 'ValidationError' error type to 'JSONSchemaValidationError' https://github.com/stac-utils/stac-validator/pull/213
12+
913
## [v3.1.0] - 2022-04-28
1014

1115
### Added

stac_validator/validate.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def extensions_validator(self, stac_type: str) -> dict:
140140
err_msg = f"{e.message}. Error is in {' -> '.join([str(i) for i in e.absolute_path])}"
141141
else:
142142
err_msg = f"{e.message} of the root of the STAC object"
143-
message = self.create_err_msg("ValidationError", err_msg)
143+
message = self.create_err_msg("JSONSchemaValidationError", err_msg)
144144
return message
145145
except Exception as e:
146146
valid = False
@@ -201,7 +201,9 @@ def recursive_validator(self, stac_type: str) -> bool:
201201
err_msg = f"{e.message}. Error is in {' -> '.join([str(i) for i in e.absolute_path])}"
202202
else:
203203
err_msg = f"{e.message} of the root of the STAC object"
204-
message.update(self.create_err_msg("ValidationError", err_msg))
204+
message.update(
205+
self.create_err_msg("JSONSchemaValidationError", err_msg)
206+
)
205207
self.message.append(message)
206208
return False
207209
message["valid_stac"] = True
@@ -305,10 +307,10 @@ def run(cls):
305307
message.update(cls.create_err_msg("OSError", str(e)))
306308
except jsonschema.exceptions.ValidationError as e:
307309
if e.absolute_path:
308-
err_msg = f"{e.message}. Error is in {' -> '.join([str(i) for i in e.absolute_path])}"
310+
err_msg = f"{e.message}. Error is in {' -> '.join([str(i) for i in e.absolute_path])} "
309311
else:
310312
err_msg = f"{e.message} of the root of the STAC object"
311-
message.update(cls.create_err_msg("ValidationError", err_msg))
313+
message.update(cls.create_err_msg("JSONSchemaValidationError", err_msg))
312314
except KeyError as e:
313315
message.update(cls.create_err_msg("KeyError", str(e)))
314316
except HTTPError as e:

tests/test_assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_assets_v090():
2222
"https://cdn.staclint.com/v0.9.0/item.json",
2323
],
2424
"valid_stac": False,
25-
"error_type": "ValidationError",
25+
"error_type": "JSONSchemaValidationError",
2626
"error_message": "-0.00751271 is less than the minimum of 0. Error is in properties -> view:off_nadir",
2727
"validation_method": "default",
2828
"assets_validated": {

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_core_bad_item_local_v090():
8383
"validation_method": "core",
8484
"schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
8585
"valid_stac": False,
86-
"error_type": "ValidationError",
86+
"error_type": "JSONSchemaValidationError",
8787
"error_message": "'id' is a required property of the root of the STAC object",
8888
}
8989
]

tests/test_custom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_custom_item_remote_schema_v080():
2020
"asset_type": "ITEM",
2121
"validation_method": "custom",
2222
"valid_stac": False,
23-
"error_type": "ValidationError",
23+
"error_type": "JSONSchemaValidationError",
2424
"error_message": "'bbox' is a required property of the root of the STAC object",
2525
}
2626
]
@@ -74,7 +74,7 @@ def test_custom_bad_item_remote_schema_v090():
7474
"validation_method": "custom",
7575
"schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
7676
"valid_stac": False,
77-
"error_type": "ValidationError",
77+
"error_type": "JSONSchemaValidationError",
7878
"error_message": "'id' is a required property of the root of the STAC object",
7979
}
8080
]
@@ -115,7 +115,7 @@ def test_custom_eo_error_v1rc2():
115115
"asset_type": "ITEM",
116116
"validation_method": "custom",
117117
"valid_stac": False,
118-
"error_type": "ValidationError",
119-
"error_message": "'panchromatic' is not one of ['coastal', 'blue', 'green', 'red', 'rededge', 'yellow', 'pan', 'nir', 'nir08', 'nir09', 'cirrus', 'swir16', 'swir22', 'lwir', 'lwir11', 'lwir12']. Error is in assets -> B8 -> eo:bands -> 0 -> common_name",
118+
"error_type": "JSONSchemaValidationError",
119+
"error_message": "'panchromatic' is not one of ['coastal', 'blue', 'green', 'red', 'rededge', 'yellow', 'pan', 'nir', 'nir08', 'nir09', 'cirrus', 'swir16', 'swir22', 'lwir', 'lwir11', 'lwir12']. Error is in assets -> B8 -> eo:bands -> 0 -> common_name ",
120120
}
121121
]

tests/test_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_local_v1rc2():
151151
"path": "tests/test_data/1rc2/extensions-collection/./proj-example/proj-example.json",
152152
"schema": ["https://stac-extensions.github.io/eo/v1.0.0/schema.json"],
153153
"valid_stac": False,
154-
"error_type": "ValidationError",
154+
"error_type": "JSONSchemaValidationError",
155155
"error_message": "'panchromatic' is not one of ['coastal', 'blue', 'green', 'red', 'rededge', 'yellow', 'pan', 'nir', 'nir08', 'nir09', 'cirrus', 'swir16', 'swir22', 'lwir', 'lwir11', 'lwir12']. Error is in assets -> B8 -> eo:bands -> 0 -> common_name",
156156
}
157157
]

tests/test_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_poorly_formatted_v090():
2020
"https://cdn.staclint.com/v0.9.0/item.json",
2121
],
2222
"valid_stac": False,
23-
"error_type": "ValidationError",
23+
"error_type": "JSONSchemaValidationError",
2424
"error_message": "-0.00751271 is less than the minimum of 0. Error is in properties -> view:off_nadir",
2525
"validation_method": "default",
2626
"links_validated": {

tests/test_recursion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_recursion_with_bad_item():
329329
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
330330
],
331331
"valid_stac": False,
332-
"error_type": "ValidationError",
332+
"error_type": "JSONSchemaValidationError",
333333
"error_message": "'id' is a required property of the root of the STAC object",
334334
},
335335
]
@@ -351,7 +351,7 @@ def test_recursion_with_missing_collection_link():
351351
],
352352
"valid_stac": False,
353353
"validation_method": "recursive",
354-
"error_type": "ValidationError",
354+
"error_type": "JSONSchemaValidationError",
355355
"error_message": "'simple-collection' should not be valid under {}. Error is in collection",
356356
},
357357
]

0 commit comments

Comments
 (0)