Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 196f0ce

Browse files
authored
Feat: Expose step run errors on context (hatchet-dev#299)
* feat: expose step run errors on context * add to on failure example * fix: wrong key * feat: log an error if no errors are found * chore: version
1 parent 3d78307 commit 196f0ce

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

examples/on_failure/worker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def step1(self, context: Context) -> None:
2525
def on_failure(self, context: Context) -> dict[str, str]:
2626
# 👀 we can do things like perform cleanup logic
2727
# or notify a user here
28+
29+
# 👀 Fetch the errors from upstream step runs from the context
30+
print(context.step_run_errors())
31+
2832
return {"status": "success"}
2933

3034

hatchet_sdk/context/context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ def child_key(self) -> str | None:
376376
def parent_workflow_run_id(self) -> str | None:
377377
return self.action.parent_workflow_run_id
378378

379+
def step_run_errors(self) -> dict[str, str]:
380+
errors = cast(dict[str, str], self.data.get("step_run_errors", {}))
381+
382+
if not errors:
383+
logger.error(
384+
"No step run errors found. `context.step_run_errors` is intended to be run in an on-failure step, and will only work on engine versions more recent than v0.53.10"
385+
)
386+
387+
return errors
388+
379389
def fetch_run_failures(self) -> list[dict[str, StrictStr]]:
380390
data = self.rest_client.workflow_run_get(self.action.workflow_run_id)
381391
other_job_runs = [

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hatchet-sdk"
3-
version = "0.43.3"
3+
version = "0.44.0"
44
description = ""
55
authors = ["Alexander Belanger <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)