Skip to content

Commit 2c6c45b

Browse files
committed
docs: added notes to ApplicationError and FailureError exception docstrings.
1 parent 3901cb7 commit 2c6c45b

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

temporalio/exceptions.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
"""Common Temporal exceptions."""
1+
"""
2+
Common Temporal exceptions.
3+
4+
# Temporal Failure
5+
6+
Most Temporal SDKs have a base class that the other Failures extend.
7+
In python, it is the ``FailureError``.
8+
9+
# Application Failure
10+
11+
Workflow, and Activity, and Nexus Operation code use Application Failures to
12+
communicate application-specific failures that happen.
13+
This is the only type of Temporal Failure created and thrown by user code.
14+
In the Python SDK, it is the ``ApplicationError``.
15+
16+
# References
17+
18+
More information can be found in the docs at
19+
https://docs.temporal.io/references/failures#workflow-execution-failures.
20+
"""
21+
22+
from temporalio.exceptions import FailureError, ApplicationError
223

324
import asyncio
425
from datetime import timedelta
@@ -23,7 +44,16 @@ def cause(self) -> Optional[BaseException]:
2344

2445

2546
class FailureError(TemporalError):
26-
"""Base for runtime failures during workflow/activity execution."""
47+
"""
48+
Base for runtime failures during workflow/activity execution.
49+
50+
This is extended by ``ApplicationError``, which can be raised in a Workflow to fail the Workflow Execution.
51+
Workflow Execution Failures put the Workflow Execution into the "Failed" state and no more attempts will
52+
be made in progressing this execution.
53+
54+
Any exception that does not extend this exception
55+
is considered a Workflow Task Failure. These types of failures will cause the Workflow Task to be retried.
56+
"""
2757

2858
def __init__(
2959
self,
@@ -71,7 +101,27 @@ def __init__(
71101

72102

73103
class ApplicationError(FailureError):
74-
"""Error raised during workflow/activity execution."""
104+
"""
105+
Error raised during workflow/activity execution.
106+
107+
Can be raised in a Workflow to fail the Workflow Execution.
108+
Workflow Execution Failures put the Workflow Execution into the "Failed" state and no more attempts will
109+
be made in progressing their execution.
110+
111+
If you are creating custom exceptions or raising typical Python-based
112+
exceptions you would either need to extend this class or
113+
explicitly state that the exception is a Workflow Execution Failure by raising a new ``ApplicationError``.
114+
115+
Any exception that does not extend this exception
116+
is considered a Workflow Task Failure. These types of failures will cause the Workflow Task to be retried.
117+
118+
# Example
119+
120+
>>> from temporalio.exceptions import ApplicationError
121+
... # ...
122+
... if isDelivery and distance.get_kilometers() > 25:
123+
... raise ApplicationError("Customer lives outside the service area")
124+
"""
75125

76126
def __init__(
77127
self,

0 commit comments

Comments
 (0)