[Mlir-commits] [mlir] b9f5b02 - [mlir][mbr] Improve diagnostics on error with `raise from`.

Ingo Müller llvmlistbot at llvm.org
Fri Jul 15 08:16:03 PDT 2022


Author: Ingo Müller
Date: 2022-07-15T15:15:58Z
New Revision: b9f5b02fd071d494f828c3c9c2b25c671a457928

URL: https://github.com/llvm/llvm-project/commit/b9f5b02fd071d494f828c3c9c2b25c671a457928
DIFF: https://github.com/llvm/llvm-project/commit/b9f5b02fd071d494f828c3c9c2b25c671a457928.diff

LOG: [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

Added: 
    

Modified: 
    mlir/utils/mbr/mbr/main.py

Removed: 
    


################################################################################
diff  --git a/mlir/utils/mbr/mbr/main.py b/mlir/utils/mbr/mbr/main.py
index b9ff9f4640b43..0f67454878bb1 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"


        


More information about the Mlir-commits mailing list