TaskException model reference¶
TaskException is the JSON-serializable record of a task or workflow failure: the exception's type, module, message, sanitized args, and formatted traceback. It is stored on task.exception (and workflow.exception) when execution fails, so failures can be inspected from any process. to_exception() rebuilds the original exception on a best-effort basis, falling back to TaskFailedError when the class cannot be imported or constructed.
sheppy.models.TaskException
¶
Bases: BaseModel
Serializable representation of an exception raised during task execution.
Captures everything needed to inspect a task failure in a JSON-serializable form, so it can be stored in any backend and reconstructed later.
| ATTRIBUTE | DESCRIPTION |
|---|---|
type |
Exception class name, e.g.
TYPE:
|
module |
Module where the exception class is defined, e.g.
TYPE:
|
message |
Exception message, i.e.
TYPE:
|
args |
Exception args, sanitized to be JSON serializable (non-serializable values are replaced with their repr).
TYPE:
|
traceback |
Full formatted traceback of the exception. None for synthesized exceptions (e.g. worker crash).
TYPE:
|
Example
from sheppy import Queue, task
@task
def failing_task():
raise ValueError("something went wrong")
q = Queue(...)
t = await q.add(failing_task())
assert t is not None
t = await q.wait_for(t)
assert t.exception is not None
print(t.exception.type) # "ValueError"
print(t.exception.message) # "something went wrong"
print(t.exception.traceback) # full formatted traceback
# best-effort reconstruction of the original exception
exc = t.exception.to_exception()
assert isinstance(exc, ValueError)
args
¶
args: tuple[Any, ...] = Field(default_factory=tuple)
tuple[Any, ...]: Exception args, sanitized to be JSON serializable.
traceback
¶
traceback: str | None = None
str|None: Full formatted traceback. None for synthesized exceptions (e.g. worker crash).
from_exception
¶
from_exception(exception: BaseException) -> TaskException
Source code in src/sheppy/models.py
118 119 120 121 122 123 124 125 126 | |
to_exception
¶
to_exception() -> Exception
Source code in src/sheppy/models.py
128 129 130 131 132 133 134 135 136 137 138 | |