Skip to content

Commit

Permalink
Better support for passing around TaskException as pickled value.
Browse files Browse the repository at this point in the history
Fixes #536
  • Loading branch information
coleifer committed Jul 14, 2020
1 parent 3c5ef64 commit 40eaf6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions huey/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class TaskLockedException(HueyException): pass
class CancelExecution(Exception): pass
class RetryTask(Exception): pass
class TaskException(Exception):
def __init__(self, metadata, *args):
self.metadata = metadata
def __init__(self, metadata=None, *args):
self.metadata = metadata or {}
super(TaskException, self).__init__(*args)

def __unicode__(self):
return self.metadata['error']
return self.metadata.get('error') or 'unknown error'
__str__ = __unicode__
16 changes: 16 additions & 0 deletions huey/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ def task_e(n):
self.assertEqual(self.huey.result_count(), 0)
self.assertEqual(len(self.huey), 0)

def test_subtask_error(self):
@self.huey.task()
def task_i(a):
raise TestError(a)

@self.huey.task()
def task_o(a):
res = task_i(a)
self.execute_next()
return res.get(blocking=True)

r = task_o(1)
self.assertTrue(self.execute_next() is None)
exc = self.trap_exception(r)
self.assertEqual(exc.metadata['error'], 'TaskException()')

def test_retry(self):
class TestException(Exception):
counter = 0
Expand Down

0 comments on commit 40eaf6a

Please sign in to comment.