Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdk-core: vdk_exception hook exit code fix #915

Merged
merged 2 commits into from
Jul 26, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List
from typing import Optional

from click import ClickException
from vdk.internal.builtin_plugins.run.run_status import ExecutionStatus
from vdk.internal.core import errors
from vdk.internal.core.errors import ErrorMessage
Expand Down Expand Up @@ -77,7 +78,11 @@ def get_exception_to_raise(self):
Returns main exception to be used as a failure reason for the data job.
"""
if self.exception:
return self.exception
return (
Exception(self.exception.message)
if isinstance(self.exception, ClickException)
else self.exception
)
step_exceptions = map(lambda x: x.exception, self.steps_list)
step_exception = next(filter(lambda e: e is not None, step_exceptions), None)
if step_exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import logging
import pathlib
import sys
from pathlib import Path
Expand All @@ -26,6 +27,8 @@
from vdk.internal.core.statestore import StateStore
from vdk.internal.plugin.plugin import PluginRegistry

log = logging.getLogger(__name__)


class NoOpStepDataJobHookImplPlugin(DataJobDefaultHookImplPlugin):
"""
Expand Down Expand Up @@ -141,12 +144,17 @@ def __enter__(self) -> IJobInput:
def __exit__(self, exc_type, exc_value, exc_traceback):
exit_code = 0
if exc_type:
cast(CoreHookSpecs, self._plugin_registry.hook()).vdk_exception(
handled = cast(CoreHookSpecs, self._plugin_registry.hook()).vdk_exception(
exception=exc_value
)
exit_code = (
exc_value.exit_code if isinstance(exc_value, ClickException) else 1
)
# if at least one hook implementation returned handled, means we do not need to log the exception
if not (True in handled):
log.exception("Exiting with exception.")
exit_code = (
exc_value.exit_code if isinstance(exc_value, ClickException) else 1
)
else:
exit_code = 0
else:
cast(JobRunHookSpecs, self._plugin_registry.hook()).finalize_job(
context=self._job_context
Expand Down