Skip to content

Commit

Permalink
Merge pull request #697 from kindlycat/sub_task_exception
Browse files Browse the repository at this point in the history
Store original metadata error when exception raised in sub task
  • Loading branch information
coleifer authored Dec 30, 2022
2 parents b85c966 + d004876 commit f3c437e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion huey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,13 @@ def build_error_result(self, task, exception):
except AttributeError: # Seems to only happen on 3.4.
tb = '- unable to resolve traceback on Python 3.4 -'

if isinstance(exception, TaskException):
error = exception.metadata.get('error') or repr(exception)
else:
error = repr(exception)

return {
'error': repr(exception),
'error': error,
'retries': task.retries,
'traceback': tb,
'task_id': task.id,
Expand Down
2 changes: 1 addition & 1 deletion huey/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def task_o(a):
r = task_o(1)
self.assertTrue(self.execute_next() is None)
exc = self.trap_exception(r)
self.assertEqual(exc.metadata['error'], 'TaskException()')
self.assertEqual(exc.metadata['error'], 'TestError(1)')

def test_retry(self):
@self.huey.task(retries=1)
Expand Down

0 comments on commit f3c437e

Please sign in to comment.