Skip to content

Use suppressed exceptions to provide detailed library loading errors#800

Merged
ktoso merged 1 commit into
swiftlang:mainfrom
sidepelican:load_error
Jun 21, 2026
Merged

Use suppressed exceptions to provide detailed library loading errors#800
ktoso merged 1 commit into
swiftlang:mainfrom
sidepelican:load_error

Conversation

@sidepelican

Copy link
Copy Markdown
Contributor

Previously, when System.loadLibrary failed, the specific underlying errors were not being exposed.

For instance, libSwiftJava depends on libFoundationEssentials, which in turn depends on libswiftSynchronization.so. If libswiftSynchronization is missing from the runtime environment, the error message would simply report a generic SwiftJava loading failure. This is confusing.

Caused by: java.lang.RuntimeException: Failed to load SwiftJava from java.library.path and JAR resources

This PR updates the loading logic to collect and expose all encountered errors by utilizing Throwable.addSuppressed().

Caused by: java.lang.RuntimeException: Failed to load 'SwiftJava'. See suppressed exceptions for details.
...
Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: library "libswiftSynchronization.so" not found: needed by /data/app/~~4oHrmhVZEl3rBmUeZO9Qxw==/com.example.flapjack.sample-oJLD0uYeGSfA89xh9utNJA==/base.apk!/lib/arm64-v8a/libFoundationEssentials.so in namespace clns-7
...
Suppressed: java.lang.RuntimeException: Expected library 'SwiftJava' ('libSwiftJava.so') was not found as resource!
...

@sidepelican sidepelican requested a review from ktoso as a code owner June 20, 2026 13:52
@ktoso

ktoso commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Good fixup, thank you

@ktoso ktoso merged commit f34064f into swiftlang:main Jun 21, 2026
41 of 42 checks passed
@sidepelican sidepelican deleted the load_error branch June 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants