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
2
23
3
24
import asyncio
4
25
from datetime import timedelta
@@ -23,7 +44,16 @@ def cause(self) -> Optional[BaseException]:
23
44
24
45
25
46
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
+ """
27
57
28
58
def __init__ (
29
59
self ,
@@ -71,7 +101,27 @@ def __init__(
71
101
72
102
73
103
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
+ """
75
125
76
126
def __init__ (
77
127
self ,
0 commit comments