Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions swf/actors/decider.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ def complete(self, task_token,
except SWFResponseError as e:
if e.error_code == 'UnknownResourceFault':
raise DoesNotExistError(
"Unable to complete decision task with token: {}.\n"
"Possible reasons: decision already completed or "
"workflow execution is closed.\n"
"Details: {}".format(task_token, e.body['message'])
"Unable to complete decision task with token: {}.\n".format(task_token),
e.body['message']
)

raise ResponseError(e.body['message'])
Expand Down Expand Up @@ -99,9 +97,8 @@ def poll(self, task_list=None,
except SWFResponseError as e:
if e.error_code == 'UnknownResourceFault':
raise DoesNotExistError(
"Unable to poll decision task.\n"
"Reason: workflow execution is probably closed.\n"
"Details: {}".format(task_token, e.body['message'])
"Unable to poll decision task.\n",
e.body['message'],
)

raise ResponseError(e.body['message'])
Expand Down
28 changes: 10 additions & 18 deletions swf/actors/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ def cancel(self, task_token, details=None):
except SWFResponseError as e:
if e.error_code == 'UnknownResourceFault':
raise DoesNotExistError(
"Unable to cancel activity task with token: {}.\n"
"Possible reasons: task already canceled or "
"workflow execution is closed.\n"
"Details: {}".format(task_token)
"Unable to cancel activity task with token: {}.\n".format(task_token),
e.body['message']
)

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

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

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

raise ResponseError(e.body['message'])
Expand Down Expand Up @@ -167,9 +160,8 @@ def poll(self, task_list=None, identity=None):
except SWFResponseError as e:
if e.error_code == 'UnknownResourceFault':
raise DoesNotExistError(
"Unable to poll activity task.\n"
"Possible reason: workflow execution is probably closed.\n"
"Details: {}".format(e.body['message'])
"Unable to poll activity task.\n",
e.body['message']
)

raise ResponseError(e.body['message'])
Expand Down
33 changes: 27 additions & 6 deletions swf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,47 @@
#
# See the file LICENSE for copying permission.

class SWFError(Exception):
def __init__(self, message, raw_error, *args):
Exception.__init__(self, message, *args)
self.kind, self.details = raw_error.split(':')

class PollTimeout(Exception):
def __repr__(self):
msg = self.message

if self.kind and self.details:
msg += '\nReason: {}, {}'.format(self.kind, self.details)

return msg

def __str__(self):
msg = self.message

if self.kind and self.details:
msg += '\nReason: {}, {}'.format(self.kind, self.details)

return msg


class PollTimeout(SWFError):
pass


class InvalidCredentialsError(Exception):
class InvalidCredentialsError(SWFError):
pass


class ResponseError(Exception):
class ResponseError(SWFError):
pass


class DoesNotExistError(Exception):
class DoesNotExistError(SWFError):
pass


class AlreadyExistsError(Exception):
class AlreadyExistsError(SWFError):
pass


class InvalidKeywordArgumentError(Exception):
class InvalidKeywordArgumentError(SWFError):
pass