Skip to content

Commit

Permalink
pass child exceptions to gokart.build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-king committed Dec 20, 2024
1 parent 19009e3 commit 3a82af9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gokart/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def __exit__(self, exception_type, exception_value, traceback):


class GokartBuildError(Exception):
pass
def __init__(self, messsage, raised_exceptions: dict[str, list[Exception]]):
super().__init__(messsage)
self.raised_exceptions = raised_exceptions


class HasLockedTaskException(Exception):
Expand Down Expand Up @@ -133,14 +135,16 @@ def build(
"""
if reset_register:
_reset_register()

with LoggerConfig(level=log_level):
task_lock_exception_raised = TaskLockExceptionRaisedFlag()
raised_exceptions: dict[str, list[Exception]] = dict()

@TaskOnKart.event_handler(luigi.Event.FAILURE)
def when_failure(task, exception):
if isinstance(exception, TaskLockException):
task_lock_exception_raised.flag = True
else:
raised_exceptions.setdefault(task.make_unique_id(), []).append(exception)

@backoff.on_exception(
partial(backoff.expo, max_value=task_lock_exception_max_wait_seconds), HasLockedTaskException, max_tries=task_lock_exception_max_tries
Expand All @@ -157,7 +161,7 @@ def _build_task():
if task_lock_exception_raised.flag:
raise HasLockedTaskException()
if result.status == luigi.LuigiStatusCode.FAILED:
raise GokartBuildError(result.summary_text)
raise GokartBuildError(result.summary_text, raised_exceptions=raised_exceptions)
return _get_output(task) if return_value else None

return _build_task()

0 comments on commit 3a82af9

Please sign in to comment.