Repository navigation
fix(core): [Throwable Boundaries 1] Rethrow fatal errors at core SDK boundaries - #6657
Draft
runningcode wants to merge 3 commits into
Draft
runningcode wants to merge 3 commits into
runningcode wants to merge 3 commits into
Conversation
The broad catches in the core SDK sit at boundaries where we can't know what the other side throws: public API entry points, user callbacks, event processors, integrations, and data written by other launches, processes or hybrid SDKs. They also swallowed OutOfMemoryError, StackOverflowError and LinkageError. Call ExceptionUtils.rethrowIfFatal first at each one, and say in a comment why it is broad and what is lost when it fails. - Integration close in Scopes.close catches LinkageError first, like Integration.register in Sentry.init, so a missing optional dependency doesn't stop the other integrations from closing. - The user-facing callbacks, ScopeCallback, EventProcessor and OptionsConfiguration document that a throwing callback only shows up in the debug log, and that fatal errors are rethrown. - Narrow the two catches whose failures are known: attaching a client report (IOException) and the envelope item meta length (Exception). - Remove the catches in ClientReportRecorder.recordLostEnvelope and recordLostEvent, which guard nothing the callees don't already catch. Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Event processors come from integrations that probe optional dependencies, as well as from the app. With rethrowIfFatal alone, a NoClassDefFoundError in one SDK processor would propagate out of every capture call to the app. Handle a LinkageError like any other processor failure instead, as Integration.register does in Sentry.init. Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
🚨 Detected changes in high risk code 🚨High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:
|
This was referenced Nov 18, 2026
Draft
5 of 9 tasks
📲 Install BuildsAndroid
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Stack (Throwable Boundaries)
📜 Description
The remaining
catch (Throwable)sites in the coresentrymodule are boundaries: public API entry points (Scopes), user callbacks, event processors, integrations, and data written by earlier launches, other processes or hybrid SDKs. They also swallowedOutOfMemoryError,StackOverflowErrorandLinkageError. This PR handles all 71 of them:ExceptionUtils.rethrowIfFatalfirst, with a comment saying why the catch is broad and what is lost when it fails.LinkageErrorarms, so a missing or mismatched optional dependency keeps the old handling:Scopes.close, around each integration'sclose(), likeIntegration.registerinSentry.init.SentryClient. Without it, aNoClassDefFoundErrorin one SDK processor would propagate out of every capture call.IOException), andSentryEnvelopeItemHeader.getMetaLength(Exception, which the item's lazy data factory declares).ClientReportRecorder.recordLostEnvelopeandrecordLostEvent, which guard nothing their callees don't already catch.debugenabled), and that fatal errors are rethrown. This follows the develop docs' "Callback Error Isolation" section:SentryOptions:BeforeSendCallback,BeforeSendTransactionCallback,BeforeSendReplayCallback,BeforeBreadcrumbCallback,OnOversizedEventCallback,OnDiscardCallback,TracesSamplerCallback,ProfilesSamplerCallback,Logs.BeforeSendLogCallback,Metrics.BeforeSendMetricCallbackSentryReplayOptions.BeforeErrorSamplingCallback,ScopeCallback.run,EventProcessor,Sentry.OptionsConfiguration.configurewithScope,withIsolationScopeandconfigureScopestill swallow the callback's non-fatal exceptions, as before.💡 Motivation and Context
rethrowIfFatalalso rethrowsLinkageError, so it could only be added once the sites where aLinkageErroris expected were narrowed. #6562 does that, so this stack is based on it. The sites that #6564 narrows are left alone here.💚 How did you test it?
:sentry:testsuite, plus:sentry:compileJavaand:sentry:javadoc.beforeSend,beforeBreadcrumb, an event processor, the traces and profiles samplers, aScopeCallbackand a client, while aRuntimeExceptionis still logged. Other tests check that aNoClassDefFoundErrorfrom one integration'sclosestill lets the next one close, and that an SDK event processor hitting aLinkageErroris skipped and the event is still sent.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
sentry-android-core, replay with NDK and SQLite, and the JVM integrations.🤖 Generated with Claude Code