swiftlang / swiftlang/swift-java

jextract: Preserve underlying exception when async closure completes exceptionally

Open
#915 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

When a Java async closure completes exceptionally (e.g. with RuntimeException), the error is currently caught in the Swift thunk and completed exceptionally on the Java future as a generic Exception:

Future<Void> future = MySwiftLibrary.asyncScheduleThrowing(() -> {
    CompletableFuture<Void> failed = new CompletableFuture<>();
    failed.completeExceptionally(new RuntimeException("Java async failed"));
    return failed;
});

assertThrows(ExecutionException.class, future::get);

Optimally, we should unwrap the ExecutionException in the Swift thunk and rethrow/preserve the underlying RuntimeException as the cause rather than wrapping it in a generic Exception.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the Swift thunk that catches exceptions from a Java async closure and trace how exceptional completion is propagated to the Java future. Reproduce the RuntimeException case from the issue and verify that the underlying exception is preserved as the cause rather than replaced by a generic Exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.