felipepessoto commented on code in PR #13822:
URL: https://github.com/apache/gluten/pull/13822#discussion_r4773889611


##########
cpp/core/jni/JniError.h:
##########
@@ -53,6 +55,41 @@ class JniExceptionUnwrapperRegistration final {
   ExceptionUnwrapper unwrap_;
 };
 
+// What a backend knows about one of its native errors. JNI_METHOD_END raises 
it as an
+// org.apache.gluten.exception.GlutenNativeException, and Java code uses these 
fields to choose the
+// exception users see, for example a Spark exception for a failed cast. 
Backends don't name Java classes.
+// The strings should be UTF-8; their bytes, including NULs, reach Java 
unchanged. They are owned, so the
+// JNI boundary uses no backend memory.
+struct JniExceptionMetadata {
+  // The backend's name for the function that failed, such as "cast", or empty 
if unknown. It can differ
+  // from the name of the Spark expression.
+  std::string functionName;
+  // The error message without its native context.
+  std::string reason;
+  // The full native diagnostic, which becomes the Java exception's message.
+  std::string diagnostic;
+};
+
+using ExceptionMetadataProvider = std::optional<JniExceptionMetadata> 
(*)(const std::exception&);
+
+// Register for the lifetime of the backend library. Called under the registry 
lock only when no Java
+// throwable is pending or carried, the callback must not call JNI and returns 
metadata for its own
+// errors (otherwise std::nullopt). If the callback throws, the boundary 
inspects and releases its
+// reference to that exception before unlocking, so unregistering waits for 
that. Other references, such
+// as a retained std::exception_ptr that the callback rethrew, remain their 
owners' responsibility.
+// Raising the GlutenNativeException is best effort: a Java exception raised 
while creating it stays
+// pending. Any other failure, including a callback exception, keeps the 
GlutenException fallback.

Review Comment:
   Done in d8c88e96b. I replaced the paragraph with an example provider and its 
registration, plus two lines on when the provider runs. The lifetime details 
remain in `JniError.cc` and `NewToGluten.md`.
   
   <sub>Auto-replied by the [GitHub Copilot app](https://gh.io/app)</sub>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to