Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions extension/android/jni/jni_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ void throwExecutorchException(uint32_t errorCode, const std::string& details) {
"org/pytorch/executorch/ExecutorchRuntimeException");

// Find the static factory method: makeExecutorchException(int, String)
static auto makeExceptionMethod = exceptionClass->getStaticMethod<
facebook::jni::local_ref<facebook::jni::JThrowable>(
int, facebook::jni::alias_ref<facebook::jni::JString>)>(
"makeExecutorchException",
"(ILjava/lang/String;)Lorg/pytorch/executorch/ExecutorchRuntimeException;");
static auto makeExceptionMethod =
exceptionClass
->getStaticMethod<facebook::jni::local_ref<facebook::jni::JThrowable>(
int, facebook::jni::alias_ref<facebook::jni::JString>)>(
"makeExecutorchException",
"(ILjava/lang/String;)Ljava/lang/RuntimeException;");

auto jDetails = facebook::jni::make_jstring(details);
// Call the factory method to create the exception object
Expand Down
Loading