Skip to content

Android: consistent error types across all modules#19099

Merged
psiddh merged 10 commits intopytorch:mainfrom
psiddh:error-consistency-training-jni
Apr 25, 2026
Merged

Android: consistent error types across all modules#19099
psiddh merged 10 commits intopytorch:mainfrom
psiddh:error-consistency-training-jni

Conversation

@psiddh
Copy link
Copy Markdown
Contributor

@psiddh psiddh commented Apr 23, 2026

TrainingModule: implement Closeable, replace Log.e + silent empty returns with IllegalStateException throws. Add checkNotDestroyed() guard on all public methods.

SGD: throw IllegalStateException instead of bare RuntimeException when optimizer is destroyed.

AsrModule: throw ExecutorchRuntimeException instead of bare RuntimeException on transcription failure.

ExecuTorchRuntime.validateFilePath: throw IllegalArgumentException instead of bare RuntimeException, with descriptive message.

JNI constructors: wrap ExecuTorchJni and ExecuTorchLlmJni constructor bodies in try-catch so C++ exceptions become ExecutorchRuntimeException instead of generic RuntimeException.

This commit was authored with the help of Claude.

TrainingModule: implement Closeable, replace Log.e + silent empty
returns with IllegalStateException throws. Add checkNotDestroyed()
guard on all public methods.

SGD: throw IllegalStateException instead of bare RuntimeException
when optimizer is destroyed.

AsrModule: throw ExecutorchRuntimeException instead of bare
RuntimeException on transcription failure.

ExecuTorchRuntime.validateFilePath: throw IllegalArgumentException
instead of bare RuntimeException, with descriptive message.

JNI constructors: wrap ExecuTorchJni and ExecuTorchLlmJni constructor
bodies in try-catch so C++ exceptions become ExecutorchRuntimeException
instead of generic RuntimeException.

This commit was authored with the help of Claude.
@psiddh psiddh requested a review from kirklandsign as a code owner April 23, 2026 22:36
Copilot AI review requested due to automatic review settings April 23, 2026 22:36
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 23, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19099

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (4 Unrelated Failures)

As of commit 1d00327 with merge base cb94506 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 23, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Native creation failure now throws ExecutorchRuntimeException with
INTERNAL error code, consistent with all other modules.

This commit was authored with the help of Claude.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns Android-side error handling by replacing generic/implicit failures with consistent, typed exceptions across Java/Kotlin and JNI layers.

Changes:

  • Wrap JNI HybridClass constructors to convert C++ exceptions into ExecutorchRuntimeException.
  • Update training APIs to implement Closeable, add destroyed-guards, and replace silent failures/logging with IllegalStateException.
  • Standardize exception types/messages across modules (IllegalStateException, IllegalArgumentException, ExecutorchRuntimeException).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
extension/android/jni/jni_layer_llama.cpp Wrap LLM JNI constructor in try/catch and translate failures to ExecutorchRuntimeException.
extension/android/jni/jni_layer.cpp Wrap Module JNI constructor in try/catch and translate failures to ExecutorchRuntimeException.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java Implement Closeable, add destroyed guard, and replace log+empty-return with exceptions.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/SGD.java Throw IllegalStateException when optimizer is destroyed.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/asr/AsrModule.kt Throw ExecutorchRuntimeException on transcription failure.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecuTorchRuntime.java Throw IllegalArgumentException with more descriptive message on invalid file paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/jni/jni_layer.cpp
Comment thread extension/android/jni/jni_layer_llama.cpp
- Fix clang-format indentation in jni_layer_llama.cpp constructor
- Add throw; after throwExecutorchException in both JNI constructors
  to ensure construction fails deterministically
- Use import for ExecutorchRuntimeException in AsrModule.kt
- Fix validateFilePath Javadoc to document IllegalArgumentException
- Split validateFilePath into specific error messages (does not exist,
  is not a file, is not readable)

This commit was authored with the help of Claude.
Copilot AI review requested due to automatic review settings April 24, 2026 00:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/jni/jni_layer_llama.cpp
psiddh added 2 commits April 23, 2026 20:30
JNI constructors now catch all native exceptions, not just std::exception.
Fix redundant fully-qualified ExecutorchRuntimeException.INTERNAL in
AsrModule.kt.

This commit was authored with the help of Claude.
This commit was authored with the help of Claude.
Copilot AI review requested due to automatic review settings April 24, 2026 06:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 24, 2026 20:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/jni/jni_layer.cpp Outdated
Comment thread extension/android/jni/jni_layer_llama.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 22:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JniException takes a jthrowable, not a string. throwExecutorchException
already throws via fbjni at the JNI boundary — no need to rethrow.

This commit was authored with the help of Claude.
@psiddh psiddh merged commit 7e2ff8a into pytorch:main Apr 25, 2026
167 of 171 checks passed
JacobSzwejbka added a commit that referenced this pull request Apr 26, 2026
## Summary

Reverts the following Android PRs:
- #19099 — Android: consistent error types across all modules
- #19124 — Android: Module implements Closeable
- #19092 — Android: improve error diagnostics for LlmModule and
exceptions
- #19028 — Ignored Module tests: provide required input tensor

Authored with Claude.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants