Skip to content

Commit 9f8be21

Browse files
committed
feat(unrelated): WorkflowExecutionAlreadyStartedError
Translate WorkflowExecutionAlreadyStartedFault into a WorkflowExecutionAlreadyStartedError exception. Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 40b4f32 commit 9f8be21

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

simpleflow/swf/mapper/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class SWFError(Exception):
12-
def __init__(self, message: str, raw_error: str = "", *args) -> None:
12+
def __init__(self, message: str = "", raw_error: str = "", *args) -> None:
1313
"""
1414
Examples:
1515
@@ -105,6 +105,10 @@ class RateLimitExceededError(SWFError):
105105
pass
106106

107107

108+
class WorkflowExecutionAlreadyStartedError(SWFError):
109+
pass
110+
111+
108112
def ignore(*args, **kwargs):
109113
return
110114

@@ -234,7 +238,7 @@ def raises(exception, when, extract: Callable[[Any], str] = str):
234238
@wraps(raises)
235239
def raises_closure(error, *args, **kwargs):
236240
if when(error, *args, **kwargs) is True:
237-
raise exception(extract(error))
241+
raise exception(extract(error)) from None
238242
raise error
239243

240244
return raises_closure

simpleflow/swf/mapper/models/workflow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AlreadyExistsError,
1414
DoesNotExistError,
1515
ResponseError,
16+
WorkflowExecutionAlreadyStartedError,
1617
extract_error_code,
1718
extract_message,
1819
raises,
@@ -219,6 +220,14 @@ def upstream(self) -> WorkflowType:
219220
qs = WorkflowTypeQuerySet(self.domain)
220221
return qs.get(self.name, self.version)
221222

223+
@exceptions.catch(
224+
ClientError,
225+
raises(
226+
WorkflowExecutionAlreadyStartedError,
227+
when=lambda error, *args, **kwargs: extract_error_code(error) == "WorkflowExecutionAlreadyStartedFault",
228+
extract=lambda *args, **kwargs: "",
229+
),
230+
)
222231
def start_execution(
223232
self,
224233
workflow_id: str | None = None,

0 commit comments

Comments
 (0)