Skip to content

Commit 4519036

Browse files
authored
Route Module.loadMethod through makeExecutorchException for native log enrichment (pytorch#20191)
Summary: `Module.loadMethod` directly constructs `ExecutorchRuntimeException`, bypassing the `makeExecutorchException` factory that enriches error details with the native log tail (added in D107196396). As a result, the high-volume SceneX XNNPACK 0x12 `loadMethod` failures (`[ExecuTorch Error 0x12] Invalid argument: Failed to load method: forward`) never capture native diagnostic context — `nativeLog=` never appears in Scuba/QPL data. Route the throw through the factory so these failures get the native log tail for triage. The change is applied to both the `xplat` and `fbcode` copies of `Module.kt` to keep them in sync, mirroring how D107196396 edited both copies of `ExecutorchRuntimeException.kt`. For error code 0x12 (`INVALID_ARGUMENT`), `makeExecutorchException` returns `ExecutorchInvalidArgumentException`, a subclass of `ExecutorchRuntimeException` that carries the same `errorCode`, so existing `catch (ExecutorchRuntimeException)` and `getErrorCode()` consumers are unaffected. The enrichment runs only on the failure path (not per-call) and uses the static `readLogBufferStatic` JNI read, which takes a separate native mutex, so it does not re-enter the `mLock` held by `loadMethod`. The change is additive: when no native logs are available the message is byte-identical to today's. This was authored with assistance from Claude. Reviewed By: SS-JIA Differential Revision: D108154606
1 parent 97c153f commit 4519036

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • extension/android/executorch_android/src/main/java/org/pytorch/executorch

extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ open class Module private constructor(moduleAbsolutePath: String, loadMode: Int,
8989
check(mHybridData.isValid) { "Module has been destroyed" }
9090
val errorCode = loadMethodNative(methodName)
9191
if (errorCode != 0) {
92-
throw ExecutorchRuntimeException(errorCode, "Failed to load method: $methodName")
92+
throw ExecutorchRuntimeException.makeExecutorchException(
93+
errorCode, "Failed to load method: $methodName")
9394
}
9495
} finally {
9596
mLock.unlock()

0 commit comments

Comments
 (0)