Skip to content

Commit 91b184b

Browse files
ref: follow Session rename in InternalSentrySdk
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ce6fc19 commit 91b184b

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ public static SentryId captureEnvelope(
225225
* treat {@code handled=false} as a crash that ends the session. Instead it:
226226
*
227227
* <ul>
228-
* <li>marks the current session as pending-unhandled and increments the error count
228+
* <li>flags the current session with a non-terminating unhandled error and increments the error
229+
* count
229230
* <li>keeps session status {@code Ok} and the same session id on the scope
230231
* <li>does not attach a session update item to this envelope
231232
* <li>does not start a new session
232-
* <li>persists the current session so pending-unhandled survives process death
233+
* <li>persists the current session so the flag survives process death
233234
* </ul>
234235
*
235236
* <p>The session is finalized later by normal lifecycle ({@code endSession} / background /
@@ -254,31 +255,31 @@ public static SentryId captureEnvelopeNonTerminating(final @NotNull byte[] envel
254255

255256
try {
256257
final @NotNull ISerializer serializer = options.getSerializer();
257-
boolean markPendingUnhandled = false;
258+
boolean hasUnhandled = false;
258259
boolean addErrorsCount = false;
259260
for (SentryEnvelopeItem item : envelope.getItems()) {
260261
final SentryEvent event = item.getEvent(serializer);
261262
if (event != null) {
262263
if (event.getUnhandledException() != null) {
263-
markPendingUnhandled = true;
264+
hasUnhandled = true;
264265
addErrorsCount = true;
265266
} else if (event.isErrored()) {
266267
addErrorsCount = true;
267268
}
268269
}
269270
}
270271

271-
if (markPendingUnhandled || addErrorsCount) {
272-
final boolean pending = markPendingUnhandled;
272+
if (hasUnhandled || addErrorsCount) {
273+
final boolean unhandled = hasUnhandled;
273274
final boolean addErrors = addErrorsCount;
274275
scopes.configureScope(
275276
scope -> {
276277
scope.withSession(
277278
session -> {
278279
if (session != null) {
279280
final boolean updated =
280-
pending
281-
? session.markPendingUnhandled()
281+
unhandled
282+
? session.recordNonTerminatingUnhandledError()
282283
: session.update(null, null, addErrors, null);
283284
if (updated && options.getEnvelopeDiskCache() instanceof EnvelopeCache) {
284285
((EnvelopeCache) options.getEnvelopeDiskCache())

‎sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class InternalSentrySdkTest {
470470
}
471471

472472
@Test
473-
fun `captureEnvelopeNonTerminating keeps the session Ok and marks it pending unhandled`() {
473+
fun `captureEnvelopeNonTerminating keeps the session Ok and flags the unhandled error`() {
474474
val fixture = Fixture()
475475
fixture.init(context)
476476

@@ -488,19 +488,19 @@ class InternalSentrySdkTest {
488488
assertThat(capturedEnvelopeItems).hasSize(1)
489489
assertThat(capturedEnvelopeItems[0].header.type).isEqualTo(SentryItemType.Event)
490490

491-
// and the session stays alive on the scope, same id, marked pending unhandled
491+
// and the session stays alive on the scope, same id, flagged with the unhandled error
492492
val scopeSession = AtomicReference<Session>()
493493
Sentry.configureScope { scope -> scopeSession.set(scope.session) }
494494
assertThat(scopeSession.get().status).isEqualTo(Session.State.Ok)
495-
assertThat(scopeSession.get().isPendingUnhandled).isTrue()
495+
assertThat(scopeSession.get().hasNonTerminatingUnhandledError()).isTrue()
496496
assertThat(scopeSession.get().sessionId).isEqualTo(originalSid.get())
497497

498498
// and it is persisted so pending survives process death
499499
val sessionFile = EnvelopeCache.getCurrentSessionFile(fixture.options.cacheDirPath!!)
500500
val persistedSession =
501501
fixture.options.serializer.deserialize(sessionFile.reader(), Session::class.java)!!
502502
assertThat(persistedSession.status).isEqualTo(Session.State.Ok)
503-
assertThat(persistedSession.isPendingUnhandled).isTrue()
503+
assertThat(persistedSession.hasNonTerminatingUnhandledError()).isTrue()
504504
assertThat(persistedSession.sessionId).isEqualTo(originalSid.get())
505505
}
506506

@@ -544,7 +544,7 @@ class InternalSentrySdkTest {
544544
val pendingSession = AtomicReference<Session>()
545545
Sentry.configureScope { scope -> pendingSession.set(scope.session) }
546546
val oldSid = pendingSession.get().sessionId
547-
assertThat(pendingSession.get().isPendingUnhandled).isTrue()
547+
assertThat(pendingSession.get().hasNonTerminatingUnhandledError()).isTrue()
548548
fixture.capturedEnvelopes.clear()
549549

550550
// when a subsequent hard crash is captured through the existing terminating API
@@ -562,14 +562,14 @@ class InternalSentrySdkTest {
562562
Session::class.java,
563563
)!!
564564
assertThat(crashedSession.status).isEqualTo(Session.State.Crashed)
565-
assertThat(crashedSession.isPendingUnhandled).isFalse()
565+
assertThat(crashedSession.hasNonTerminatingUnhandledError()).isFalse()
566566
assertThat(crashedSession.sessionId).isEqualTo(oldSid)
567567

568568
// and a new Ok session with a different id is active
569569
val activeSession = AtomicReference<Session>()
570570
Sentry.configureScope { scope -> activeSession.set(scope.session) }
571571
assertThat(activeSession.get().status).isEqualTo(Session.State.Ok)
572-
assertThat(activeSession.get().isPendingUnhandled).isFalse()
572+
assertThat(activeSession.get().hasNonTerminatingUnhandledError()).isFalse()
573573
assertThat(activeSession.get().sessionId).isNotEqualTo(oldSid)
574574
}
575575

0 commit comments

Comments
 (0)