Skip to content

Commit 55fd40d

Browse files
adinauerclaude
andcommitted
fix(callbacks): Preserve Apollo 2 error handling
Keep Apollo 2's existing Exception boundary unchanged so non-Exception errors retain their released behavior. Limit the broader nonfatal Throwable handling to callback guards introduced by the unreleased stack. Refs #6081 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d04cc24 commit 55fd40d

2 files changed

Lines changed: 2 additions & 33 deletions

File tree

‎sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import io.sentry.SpanStatus
2626
import io.sentry.TypeCheckHint.APOLLO_REQUEST
2727
import io.sentry.TypeCheckHint.APOLLO_RESPONSE
2828
import io.sentry.clientreport.DiscardReason
29-
import io.sentry.util.ExceptionUtils
3029
import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion
3130
import io.sentry.util.SpanUtils
3231
import io.sentry.util.TracingUtils
@@ -181,8 +180,7 @@ class SentryApolloInterceptor(
181180
val wasSampled = span.isSampled == true
182181
try {
183182
newSpan = beforeSpan.execute(span, request, response)
184-
} catch (@Suppress("TooGenericExceptionCaught") e: Throwable) {
185-
ExceptionUtils.rethrowIfFatal(e)
183+
} catch (e: Exception) {
186184
span.spanContext.sampled = false
187185
if (wasSampled) {
188186
scopes.options.clientReportRecorder.recordLostEvent(

‎sentry-apollo/src/test/java/io/sentry/apollo/SentryApolloInterceptorTest.kt‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ package io.sentry.apollo
33
import com.apollographql.apollo.ApolloClient
44
import com.apollographql.apollo.coroutines.await
55
import com.apollographql.apollo.exception.ApolloException
6-
import com.apollographql.apollo.interceptor.ApolloInterceptor.CallBack
7-
import com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorRequest
8-
import com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorResponse
9-
import com.apollographql.apollo.interceptor.ApolloInterceptorChain
106
import com.google.common.truth.Truth.assertThat
117
import io.sentry.BaggageHeader
128
import io.sentry.Breadcrumb
@@ -33,7 +29,6 @@ import io.sentry.util.ApolloPlatformTestManipulator
3329
import java.util.concurrent.TimeUnit
3430
import kotlin.test.Test
3531
import kotlin.test.assertEquals
36-
import kotlin.test.assertFailsWith
3732
import kotlin.test.assertNotNull
3833
import kotlin.test.assertNull
3934
import kotlin.test.assertTrue
@@ -279,7 +274,7 @@ class SentryApolloInterceptorTest {
279274

280275
@Test
281276
fun `when beforeSpan throws, drops span and preserves response`(): Unit = runBlocking {
282-
val failure = AssertionError("callback failed")
277+
val failure = IllegalStateException("callback failed")
283278
val logger = mock<ILogger>()
284279
fixture.options.isDebug = true
285280
fixture.options.setLogger(logger)
@@ -313,30 +308,6 @@ class SentryApolloInterceptorTest {
313308
)
314309
}
315310

316-
@Test
317-
fun `fatal error from beforeSpan is not swallowed`() {
318-
val failure = OutOfMemoryError("callback failed")
319-
val tx =
320-
SentryTracer(TransactionContext("op", "desc", TracesSamplingDecision(true)), fixture.scopes)
321-
whenever(fixture.scopes.span).thenReturn(tx)
322-
val interceptor = SentryApolloInterceptor(fixture.scopes) { _, _, _ -> throw failure }
323-
val request = InterceptorRequest.builder(LaunchDetailsQuery.builder().id("83").build()).build()
324-
val chain = mock<ApolloInterceptorChain>()
325-
doAnswer {
326-
it.getArgument<CallBack>(2).onResponse(InterceptorResponse(null))
327-
null
328-
}
329-
.whenever(chain)
330-
.proceedAsync(any(), any(), any())
331-
332-
val thrown =
333-
assertFailsWith<OutOfMemoryError> {
334-
interceptor.interceptAsync(request, chain, { it.run() }, mock())
335-
}
336-
337-
assertThat(thrown).isSameInstanceAs(failure)
338-
}
339-
340311
@Test
341312
fun `adds breadcrumb when http calls succeeds`() {
342313
executeQuery()

0 commit comments

Comments
 (0)