Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Commit 6ff6920

Browse files
author
Oleiade
committed
Merge branch 'develop' of github.com:botify-labs/python-simple-workflow into develop
2 parents 20edddd + c5dded5 commit 6ff6920

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

swf/actors/decider.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ def complete(self, task_token,
4444
except SWFResponseError as e:
4545
if e.error_code == 'UnknownResourceFault':
4646
raise DoesNotExistError(
47-
"Unable to complete decision task with token: {}.\n"
48-
"Possible reasons: decision already completed or "
49-
"workflow execution is closed.\n"
50-
"Details: {}".format(task_token, e.body['message'])
47+
"Unable to complete decision task with token: {}.\n".format(task_token),
48+
e.body['message']
5149
)
5250

5351
raise ResponseError(e.body['message'])
@@ -99,9 +97,8 @@ def poll(self, task_list=None,
9997
except SWFResponseError as e:
10098
if e.error_code == 'UnknownResourceFault':
10199
raise DoesNotExistError(
102-
"Unable to poll decision task.\n"
103-
"Reason: workflow execution is probably closed.\n"
104-
"Details: {}".format(task_token, e.body['message'])
100+
"Unable to poll decision task.\n",
101+
e.body['message'],
105102
)
106103

107104
raise ResponseError(e.body['message'])

swf/actors/worker.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ def cancel(self, task_token, details=None):
4747
except SWFResponseError as e:
4848
if e.error_code == 'UnknownResourceFault':
4949
raise DoesNotExistError(
50-
"Unable to cancel activity task with token: {}.\n"
51-
"Possible reasons: task already canceled or "
52-
"workflow execution is closed.\n"
53-
"Details: {}".format(task_token)
50+
"Unable to cancel activity task with token: {}.\n".format(task_token),
51+
e.body['message']
5452
)
5553

5654
raise ResponseError(e.body['message'])
@@ -72,10 +70,8 @@ def complete(self, task_token, result=None):
7270
except SWFResponseError as e:
7371
if e.error_code == 'UnknownResourceFault':
7472
raise DoesNotExistError(
75-
"Unable to complete activity task with token: {}.\n"
76-
"Possible reasons: task already completed or "
77-
"workflow execution is closed.\n"
78-
"Details: {}".format(task_token, e.body['message'])
73+
"Unable to complete activity task with token: {}.\n".format(task_token),
74+
e.body['message']
7975
)
8076

8177
raise ResponseError(e.body['message'])
@@ -101,10 +97,8 @@ def fail(self, task_token, details=None, reason=None):
10197
except SWFResponseError as e:
10298
if e.error_code == 'UnknownResourceFault':
10399
raise DoesNotExistError(
104-
"Unable to fail activity task with token: {}.\n"
105-
"Possible reasons: task already failed or "
106-
"workflow execution is closed"
107-
"Details: {}".format(task_token, e.body['message'])
100+
"Unable to fail activity task with token: {}.\n".format(task_token),
101+
e.body['message']
108102
)
109103

110104
raise ResponseError(e.body['message'])
@@ -126,9 +120,8 @@ def heartbeat(self, task_token, details=None):
126120
except SWFResponseError as e:
127121
if e.error_code == 'UnknownResourceFault':
128122
raise DoesNotExistError(
129-
"Unable to send activity task {} heartbeat.\n"
130-
"Possible reason: workflow execution is closed.\n"
131-
"Details: {}".format(task_token, e.body['message'])
123+
"Unable to send activity task {} heartbeat.\n".format(task_token),
124+
e.body['message']
132125
)
133126

134127
raise ResponseError(e.body['message'])
@@ -167,9 +160,8 @@ def poll(self, task_list=None, identity=None):
167160
except SWFResponseError as e:
168161
if e.error_code == 'UnknownResourceFault':
169162
raise DoesNotExistError(
170-
"Unable to poll activity task.\n"
171-
"Possible reason: workflow execution is probably closed.\n"
172-
"Details: {}".format(e.body['message'])
163+
"Unable to poll activity task.\n",
164+
e.body['message']
173165
)
174166

175167
raise ResponseError(e.body['message'])

swf/exceptions.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,47 @@
55
#
66
# See the file LICENSE for copying permission.
77

8+
class SWFError(Exception):
9+
def __init__(self, message, raw_error, *args):
10+
Exception.__init__(self, message, *args)
11+
self.kind, self.details = raw_error.split(':')
812

9-
class PollTimeout(Exception):
13+
def __repr__(self):
14+
msg = self.message
15+
16+
if self.kind and self.details:
17+
msg += '\nReason: {}, {}'.format(self.kind, self.details)
18+
19+
return msg
20+
21+
def __str__(self):
22+
msg = self.message
23+
24+
if self.kind and self.details:
25+
msg += '\nReason: {}, {}'.format(self.kind, self.details)
26+
27+
return msg
28+
29+
30+
class PollTimeout(SWFError):
1031
pass
1132

1233

13-
class InvalidCredentialsError(Exception):
34+
class InvalidCredentialsError(SWFError):
1435
pass
1536

1637

17-
class ResponseError(Exception):
38+
class ResponseError(SWFError):
1839
pass
1940

2041

21-
class DoesNotExistError(Exception):
42+
class DoesNotExistError(SWFError):
2243
pass
2344

2445

25-
class AlreadyExistsError(Exception):
46+
class AlreadyExistsError(SWFError):
2647
pass
2748

2849

29-
class InvalidKeywordArgumentError(Exception):
50+
class InvalidKeywordArgumentError(SWFError):
3051
pass

0 commit comments

Comments
 (0)