[Mlir-commits] [mlir] [mlir][python] Propagate error diagnostics when an op couldn't be created. (PR #169499)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 25 06:35:48 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Benjamin Chetioui (bchetioui)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/169499.diff


1 Files Affected:

- (modified) mlir/lib/Bindings/Python/IRCore.cpp (+2-1) 


``````````diff
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index b5720b7ad8b21..fd091eb8501a3 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1608,9 +1608,10 @@ nb::object PyOperation::create(std::string_view name,
   }
 
   // Construct the operation.
+  PyMlirContext::ErrorCapture errors(location.getContext());
   MlirOperation operation = mlirOperationCreate(&state);
   if (!operation.ptr)
-    throw nb::value_error("Operation creation failed");
+    throw MLIRError("Operation creation failed", errors.take());
   PyOperationRef created =
       PyOperation::createDetached(location->getContext(), operation);
   maybeInsertOperation(created, maybeIp);

``````````

</details>


https://github.com/llvm/llvm-project/pull/169499


More information about the Mlir-commits mailing list