Skip to content

Commit f5940da

Browse files
authored
More informative stack trace for benchmark data generation (SciTools#6524)
* More informative traceback for benchmark data gen. * Use subprocess text output for benchmark data gen. * Clearer error handling code. * What's New entry.
1 parent 3c576e6 commit f5940da

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

benchmarks/benchmarks/generate_data/__init__.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
REUSE_DATA = True
6060

6161

62+
class DataGenerationError(Exception):
63+
"""Exception raised for errors during data generation."""
64+
65+
pass
66+
67+
6268
def run_function_elsewhere(func_to_run, *args, **kwargs):
6369
"""Run a given function using the :const:`DATA_GEN_PYTHON` executable.
6470
@@ -92,9 +98,19 @@ def run_function_elsewhere(func_to_run, *args, **kwargs):
9298
f"{func_to_run.__name__}(" + ",".join(func_call_term_strings) + ")"
9399
)
94100
python_string = "\n".join([func_string, func_call_string])
95-
result = run(
96-
[DATA_GEN_PYTHON, "-c", python_string], capture_output=True, check=True
97-
)
101+
102+
try:
103+
result = run(
104+
[DATA_GEN_PYTHON, "-c", python_string],
105+
capture_output=True,
106+
check=True,
107+
text=True,
108+
)
109+
except CalledProcessError as error_:
110+
# From None 'breaks' the error chain - we don't want the original
111+
# traceback since it is long and confusing.
112+
raise DataGenerationError(error_.stderr) from None
113+
98114
return result.stdout
99115

100116

benchmarks/benchmarks/generate_data/stock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _external(func_name_, temp_file_dir, **kwargs_):
4545
temp_file_dir=str(BENCHMARK_DATA),
4646
**kwargs,
4747
)
48-
Path(actual_path.decode()).replace(save_path)
48+
Path(actual_path).replace(save_path)
4949
return save_path
5050

5151

docs/src/whatsnew/latest.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ This document explains the changes made to Iris for this release
107107
#. `@trexfeathers`_ added a CI workflow to quickly validate that the
108108
benchmarking setup is still working. (:pull:`6496`)
109109

110+
#. `@trexfeathers`_ improved the stack trace for errors that occur during
111+
benchmark data generation, showing developers the root problem at-a-glance
112+
without needing local replication. (:pull:`6524`)
113+
110114

111115
.. comment
112116
Whatsnew author names (@github name) in alphabetical order. Note that,

0 commit comments

Comments
 (0)