Skip to content

Commit 2241e27

Browse files
committed
refine the bad path
1 parent 8d17e5b commit 2241e27

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mlir/lib/Bindings/Python/Pass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
196196
nb::delattr(callable, mlirExternalPassAttr);
197197
};
198198
nb::setattr(run, "signal_pass_failure", nb::cpp_function([run]() {
199-
nb::capsule cap = run.attr(mlirExternalPassAttr);
199+
nb::capsule cap;
200+
try {
201+
cap = run.attr(mlirExternalPassAttr);
202+
} catch (nb::python_error &e) {
203+
throw std::runtime_error(
204+
"signal_pass_failure() should always be called "
205+
"from the __call__ method");
206+
}
200207
mlirExternalPassSignalFailure(
201208
MlirExternalPass{cap.data()});
202209
}));

mlir/test/python/python_pass.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,9 @@ def __call__(self, m):
103103
pm.run(module)
104104
except Exception as e:
105105
print(f"caught exception: {e}")
106+
107+
# CHECK: caught exception: signal_pass_failure() should always be called from the __call__ method
108+
try:
109+
custom_pass_that_fails.signal_pass_failure()
110+
except Exception as e:
111+
print(f"caught exception: {e}")

0 commit comments

Comments
 (0)