From 5912bfdab15fe7a9febddfd3e60d8c1a669abc9b Mon Sep 17 00:00:00 2001 From: Siddartha Pothapragada Date: Mon, 22 Sep 2025 13:42:57 -0700 Subject: [PATCH] ExecutorchRuntimeException: Update the exception return type Summary: Fix the JNI layer at the time of throwing the exception. Change the return type from 'ExecutorchRuntimeException' to 'RuntimeException' Also disable readLogBuffer from exception flow , A follow up change will address this. This way it keeps this change to a minimum and unblocks few Teams for now Differential Revision: D82995994 --- .../executorch/ExecutorchRuntimeException.java | 18 ++++++++++-------- extension/android/jni/jni_helper.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java index e180efcdfca..c036ecefa76 100644 --- a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java +++ b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java @@ -75,6 +75,7 @@ public class ExecutorchRuntimeException extends RuntimeException { } static class ErrorHelper { + private static final boolean ENABLE_READ_LOG_BUFFER = false; // Reusable StringBuilder instance private static final StringBuilder sb = new StringBuilder(); @@ -92,14 +93,15 @@ static String formatMessage(int errorCode, String details) { .append("] ") .append(baseMessage) .append(": ") - .append(details) - .append("\nDetailed Logs:\n"); - - try { - String[] logEntries = readLogBuffer(); // JNI call - formatLogEntries(sb, logEntries); - } catch (Exception e) { - sb.append("Failed to retrieve detailed logs: ").append(e.getMessage()); + .append(details); + if (ENABLE_READ_LOG_BUFFER) { + try { + sb.append("\nDetailed Logs:\n"); + String[] logEntries = readLogBuffer(); // JNI call + formatLogEntries(sb, logEntries); + } catch (Exception e) { + sb.append("Failed to retrieve detailed logs: ").append(e.getMessage()); + } } return sb.toString(); diff --git a/extension/android/jni/jni_helper.cpp b/extension/android/jni/jni_helper.cpp index a8fb2aeddcf..9bf1c3efbf5 100644 --- a/extension/android/jni/jni_helper.cpp +++ b/extension/android/jni/jni_helper.cpp @@ -23,7 +23,7 @@ void throwExecutorchException(uint32_t errorCode, const std::string& details) { facebook::jni::local_ref( int, facebook::jni::alias_ref)>( "makeExecutorchException", - "(ILjava/lang/String;)Lorg/pytorch/executorch/ExecutorchRuntimeException;"); + "(ILjava/lang/String;)Ljava/lang/RuntimeException;"); auto jDetails = facebook::jni::make_jstring(details); // Call the factory method to create the exception object