← Back to Pull requests

Improved error handling in JExtract JNI mode #928

Merged
madsodgaard merged 23 files (706 lines) on Oct 09, 2026 05:30 UTC
View on GitHub
madsodgaard madsodgaard commented on Oct 05, 2026 11:15 UTC
Author

Fixes #826

Currently, the only way to handle specific errors in the JExtract JNI mode, is to do a string "contains" against the Exception message. This is quite flakey, and not a nice experience for Java developers.

This PR makes extracted Error types extend Exception itself, which means Java developers can catch Swift errors as normal Java exceptions. For typed throws we also explicitly can state that the Java method throws a specific exception.

Also introduces a AnySwiftError, which is thrown when we cannot extract a concrete user Error type.

Diff: 706 lines (+681 / -25) across 23 files Reviewer: ktoso Review duration: 5415m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.71) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 706 lines diff across 23 files
0.71
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
88%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.393
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
6 items
ktoso ktoso commented on code on Oct 05, 2026 11:26 UTC
Code Review
Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesJextract.md:1
@@ -153,6 +154,32 @@ In JNI mode the exception type is `Exception`; in FFM mode it is `SwiftJavaError
    }
 }
 
+#### Errors in JNI mode
+
+In JNI mode, extracted Swift types that conform to `Error` or `LocalizedError` are generated as Java classes
+extending `org.swift.swiftkit.core.SwiftError`, which is a `java.lang.Exception`.

extending `org.swift.swiftkit.core.SwiftJavaErrorException`, which is a `java.lang.Exception`.

no?

madsodgaard madsodgaard commented on code on Oct 05, 2026 11:28 UTC
Code Review
Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesJextract.md:1
@@ -153,6 +154,32 @@ In JNI mode the exception type is `Exception`; in FFM mode it is `SwiftJavaError
    }
 }
 
+#### Errors in JNI mode
+
+In JNI mode, extracted Swift types that conform to `Error` or `LocalizedError` are generated as Java classes
+extending `org.swift.swiftkit.core.SwiftError`, which is a `java.lang.Exception`.

SwiftError is correct, that is the abstract class that all the errors extend. SwiftJavaErrorException (which I am renaming to AnySwiftError) is a concrete class, that is thrown when we cannot extract the concrete Error type.

ktoso ktoso commented on code on Oct 05, 2026 11:38 UTC
Code Review
Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesJextract.md:1
@@ -153,6 +154,32 @@ In JNI mode the exception type is `Exception`; in FFM mode it is `SwiftJavaError
    }
 }
 
+#### Errors in JNI mode
+
+In JNI mode, extracted Swift types that conform to `Error` or `LocalizedError` are generated as Java classes
+extending `org.swift.swiftkit.core.SwiftError`, which is a `java.lang.Exception`.

If they are exceptions they should end with Exception please; so ...ErrorException etc, in order to not confuse Java users - they expect to only catch things ending with ...Exception, it's be weird to catch things that are not "exception" named

madsodgaard madsodgaard commented on code on Oct 05, 2026 11:39 UTC
Code Review
Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesJextract.md:1
@@ -153,6 +154,32 @@ In JNI mode the exception type is `Exception`; in FFM mode it is `SwiftJavaError
    }
 }
 
+#### Errors in JNI mode
+
+In JNI mode, extracted Swift types that conform to `Error` or `LocalizedError` are generated as Java classes
+extending `org.swift.swiftkit.core.SwiftError`, which is a `java.lang.Exception`.

Makes sense. The rename was to not clash with FFM's SwiftJavaErrorException.

How about SwiftErrorException?

ktoso ktoso commented on code on Oct 07, 2026 04:51 UTC
Code Review
Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesJextract.md:1
@@ -153,6 +154,32 @@ In JNI mode the exception type is `Exception`; in FFM mode it is `SwiftJavaError
    }
 }
 
+#### Errors in JNI mode
+
+In JNI mode, extracted Swift types that conform to `Error` or `LocalizedError` are generated as Java classes
+extending `org.swift.swiftkit.core.SwiftError`, which is a `java.lang.Exception`.

Yeah that sounds good

Reviewers
Assignees
madsodgaard madsodgaard
Labels
risk: low confidence: 88.2% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 70.8% (HIGH) · Higher = larger blast radius
70.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 88.2% · Lower = rushed or shallow review
88.2%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 8.3% · Safe to merge
8.3%