Skip to content

Commit 41d13a7

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

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

temporalio/exceptions.py

+51-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
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+
"""
221

322
import asyncio
423
from datetime import timedelta
@@ -23,7 +42,16 @@ def cause(self) -> Optional[BaseException]:
2342

2443

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

2856
def __init__(
2957
self,
@@ -71,7 +99,27 @@ def __init__(
7199

72100

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

76124
def __init__(
77125
self,

0 commit comments

Comments
 (0)