Skip to content

Commit c60aee8

Browse files
jsignellgadomski
authored andcommitted
Give more informative validation errors
1 parent 9003b90 commit c60aee8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

stactask/task.py

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def items(self) -> ItemCollection:
157157

158158
@classmethod
159159
def validate(cls, payload: Dict[str, Any]) -> bool:
160+
"""Validates the payload and returns True if valid. If invalid, raises
161+
``stactask.exceptions.FailedValidation`` or returns False."""
160162
# put validation logic on input Items and process definition here
161163
return True
162164

tests/tasks.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List
22

33
from stactask import Task
4+
from stactask.exceptions import FailedValidation
45

56

67
class NothingTask(Task):
@@ -17,7 +18,9 @@ class FailValidateTask(Task):
1718

1819
@classmethod
1920
def validate(self, payload: Dict[str, Any]) -> bool:
20-
return False
21+
if payload:
22+
raise FailedValidation("Extra context about what went wrong")
23+
return True
2124

2225
def process(self, **kwargs: Any) -> List[Dict[str, Any]]:
2326
return self.items_as_dicts

tests/test_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_task_init(nothing_task: Task) -> None:
4141

4242

4343
def test_failed_validation(items: Dict[str, Any]) -> None:
44-
with pytest.raises(FailedValidation):
44+
with pytest.raises(FailedValidation, match="Extra context"):
4545
FailValidateTask(items)
4646

4747

0 commit comments

Comments
 (0)