Skip to content

Commit

Permalink
vdk-core: relevant info in step result
Browse files Browse the repository at this point in the history
Why?

Sometimes the exact errors in user code are hard
to find in the stack trace

What?

Print relevant information from stack trace in
step results

How was this tested?

Ran locally
Functional test

What kind of change is this?

Feature/non-breaking

Signed-off-by: Dilyan Marinov <[email protected]>
  • Loading branch information
Dilyan Marinov committed Jan 29, 2024
1 parent ed8abf4 commit 8ac66dd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
32 changes: 30 additions & 2 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 Down Expand Up @@ -143,14 +144,41 @@ def __log_exec_result(self, execution_result: ExecutionResult) -> None:

@staticmethod
def __log_short_exec_result(execution_result):
def extract_relevant_lines(step):
out = []
if step.exception:
call_list = traceback.format_tb(step.exception.__traceback__)

for i, line in enumerate(call_list):
# Check if the step name is in the line
if step.name in line:
out.append(line)
j = i + 1
# Pull in subsequent relevant lines
# that do not come from another file
while j < len(call_list) and not re.match(
r'^\s*File "', call_list[j]
):
out.append(call_list[j])
j += 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()}/jobs/fail-job/1_step.py", line 7, in run
raise ArithmeticError("cannot do math :(")
ArithmeticError: cannot do math :(
"""
assert expected in result.output

0 comments on commit 8ac66dd

Please sign in to comment.