diff options
author | Ingo Müller <ingomueller@google.com> | 2022-07-14 12:17:29 +0000 |
---|---|---|
committer | Ingo Müller <ingomueller@google.com> | 2022-07-15 15:15:58 +0000 |
commit | b9f5b02fd071d494f828c3c9c2b25c671a457928 (patch) | |
tree | 8ead9be1d23bebaaa1cb5e5f4e16304b882a801a /mlir/utils | |
parent | 2b2697b7d79c510ff6f72d8612033c1d253a78a1 (diff) | |
download | llvm-b9f5b02fd071d494f828c3c9c2b25c671a457928.tar.gz |
[mlir][mbr] Improve diagnostics on error with `raise from`.
This commit extends the `raise` statements on errors in user-provided
code with `from e` clauses that attach the original exception to the one
being raised. This allows to debug the root cause of the error more
easily.
Reviewed By: SaurabhJha
Differential Revision: https://reviews.llvm.org/D129762
Diffstat (limited to 'mlir/utils')
-rw-r--r-- | mlir/utils/mbr/mbr/main.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/mlir/utils/mbr/mbr/main.py b/mlir/utils/mbr/mbr/main.py index b9ff9f4640b4..0f67454878bb 100644 --- a/mlir/utils/mbr/mbr/main.py +++ b/mlir/utils/mbr/mbr/main.py @@ -36,16 +36,17 @@ def main(top_level_path, stop_on_error): for benchmark_function in benchmark_functions: try: compiler, runner = benchmark_function() - except (TypeError, ValueError): + except (TypeError, ValueError) as e: error_message = ( - f"benchmark_function '{benchmark_function.__name__}'" - f" must return a two tuple value (compiler, runner)." + f"Obtaining compiler and runner failed because of {e}." + f" Benchmark function '{benchmark_function.__name__}'" + f" must return a two-tuple value (compiler, runner)." ) if stop_on_error is False: print(error_message, file=sys.stderr) continue else: - raise AssertionError(error_message) + raise AssertionError(error_message) from e measurements_ns = np.array([]) if compiler: start_compile_time_s = time.time() @@ -60,7 +61,7 @@ def main(top_level_path, stop_on_error): print(error_message, file=sys.stderr) continue else: - raise AssertionError(error_message) + raise AssertionError(error_message) from e total_compile_time_s = time.time() - start_compile_time_s runner_args = (compiled_callable,) else: @@ -80,7 +81,7 @@ def main(top_level_path, stop_on_error): # and continuing forward. break else: - raise AssertionError(error_message) + raise AssertionError(error_message) from e if not isinstance(measurement_ns, int): error_message = ( f"Expected benchmark runner function" |