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: relevant info in step result #3062

Merged
merged 1 commit into from
Feb 1, 2024
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
33 changes: 30 additions & 3 deletions projects/vdk-core/src/vdk/internal/builtin_plugins/run/cli_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pathlib
import re
import sys
import traceback
from typing import cast
from typing import Dict
from typing import List
Expand All @@ -18,6 +19,7 @@
from vdk.internal.builtin_plugins.run import job_input_error_classifier
from vdk.internal.builtin_plugins.run.data_job import DataJobFactory
from vdk.internal.builtin_plugins.run.execution_results import ExecutionResult
from vdk.internal.builtin_plugins.run.execution_results import StepResult
from vdk.internal.builtin_plugins.run.execution_tracking import (
ExecutionTrackingPlugin,
)
Expand Down Expand Up @@ -143,15 +145,40 @@ def __log_exec_result(self, execution_result: ExecutionResult) -> None:
log.info(f"Data Job execution summary: {execution_result}")

@staticmethod
def __log_short_exec_result(execution_result):
def __log_short_exec_result(execution_result: ExecutionResult):
def extract_relevant_lines(step: StepResult) -> List[str]:
out = []
if step.exception:
call_list = traceback.format_tb(step.exception.__traceback__)

for line_index, line in enumerate(call_list):
# Check if the step name is in the line
if step.name in line:
out.append(line)
next_line_index = line_index + 1
# Pull in subsequent relevant lines
# that do not come from another file
while next_line_index < len(call_list) and not re.match(
r'^\s*File "', call_list[next_line_index]
):
out.append(call_list[next_line_index])
next_line_index += 1
# add the exception type and message
out.append(f"{type(step.exception).__name__}: {str(step.exception)}")
return out

log.info(
"Job execution result: "
+ execution_result.status.upper()
+ "\n"
+ "Steps list:\n"
+ "Step results:\n"
+ "".join(
[
step.name + " - " + step.status.upper() + "\n"
step.name
+ " - "
+ step.status.upper()
+ "\n"
+ "".join(extract_relevant_lines(step))
for step in execution_result.steps_list
]
)
Expand Down
15 changes: 15 additions & 0 deletions projects/vdk-core/tests/functional/run/test_run_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,18 @@ def test_error_from_pandas_user_error(tmp_termination_msg_file):
assert _get_job_status(tmp_termination_msg_file) == "User error"
assert '"blamee": "User Error"' in result.output
assert '"exception_name": "KeyError"' in result.output


def test_run_simple_job_summary(tmp_termination_msg_file):
runner = CliEntryBasedTestRunner()

result: Result = runner.invoke(["run", util.job_path("fail-job")])
cli_assert_equal(1, result)
expected = f"""
Step results:
1_step.py - ERROR
File "{os.getcwd()}/tests/functional/run/jobs/fail-job/1_step.py", line 7, in run
raise ArithmeticError("cannot do math :(")
ArithmeticError: cannot do math :(
"""
assert expected in result.output
Loading