Skip to content

Commit 583e85a

Browse files
Merge main into person/hduygu/confluence-reader-example
2 parents 6504b4f + 656ba0c commit 583e85a

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

projects/vdk-core/src/vdk/internal/builtin_plugins/run/cli_run.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pathlib
88
import re
99
import sys
10+
import traceback
1011
from typing import cast
1112
from typing import Dict
1213
from typing import List
@@ -18,6 +19,7 @@
1819
from vdk.internal.builtin_plugins.run import job_input_error_classifier
1920
from vdk.internal.builtin_plugins.run.data_job import DataJobFactory
2021
from vdk.internal.builtin_plugins.run.execution_results import ExecutionResult
22+
from vdk.internal.builtin_plugins.run.execution_results import StepResult
2123
from vdk.internal.builtin_plugins.run.execution_tracking import (
2224
ExecutionTrackingPlugin,
2325
)
@@ -143,15 +145,40 @@ def __log_exec_result(self, execution_result: ExecutionResult) -> None:
143145
log.info(f"Data Job execution summary: {execution_result}")
144146

145147
@staticmethod
146-
def __log_short_exec_result(execution_result):
148+
def __log_short_exec_result(execution_result: ExecutionResult):
149+
def extract_relevant_lines(step: StepResult) -> List[str]:
150+
out = []
151+
if step.exception:
152+
call_list = traceback.format_tb(step.exception.__traceback__)
153+
154+
for line_index, line in enumerate(call_list):
155+
# Check if the step name is in the line
156+
if step.name in line:
157+
out.append(line)
158+
next_line_index = line_index + 1
159+
# Pull in subsequent relevant lines
160+
# that do not come from another file
161+
while next_line_index < len(call_list) and not re.match(
162+
r'^\s*File "', call_list[next_line_index]
163+
):
164+
out.append(call_list[next_line_index])
165+
next_line_index += 1
166+
# add the exception type and message
167+
out.append(f"{type(step.exception).__name__}: {str(step.exception)}")
168+
return out
169+
147170
log.info(
148171
"Job execution result: "
149172
+ execution_result.status.upper()
150173
+ "\n"
151-
+ "Steps list:\n"
174+
+ "Step results:\n"
152175
+ "".join(
153176
[
154-
step.name + " - " + step.status.upper() + "\n"
177+
step.name
178+
+ " - "
179+
+ step.status.upper()
180+
+ "\n"
181+
+ "".join(extract_relevant_lines(step))
155182
for step in execution_result.steps_list
156183
]
157184
)

projects/vdk-core/tests/functional/run/test_run_errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,18 @@ def test_error_from_pandas_user_error(tmp_termination_msg_file):
229229
assert _get_job_status(tmp_termination_msg_file) == "User error"
230230
assert '"blamee": "User Error"' in result.output
231231
assert '"exception_name": "KeyError"' in result.output
232+
233+
234+
def test_run_simple_job_summary(tmp_termination_msg_file):
235+
runner = CliEntryBasedTestRunner()
236+
237+
result: Result = runner.invoke(["run", util.job_path("fail-job")])
238+
cli_assert_equal(1, result)
239+
expected = f"""
240+
Step results:
241+
1_step.py - ERROR
242+
File "{os.getcwd()}/tests/functional/run/jobs/fail-job/1_step.py", line 7, in run
243+
raise ArithmeticError("cannot do math :(")
244+
ArithmeticError: cannot do math :(
245+
"""
246+
assert expected in result.output

0 commit comments

Comments
 (0)