Skip to content

Commit 81822da

Browse files
ref: follow Session rename in EnvelopeCache
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 52bf486 commit 81822da

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

‎sentry/src/main/java/io/sentry/cache/EnvelopeCache.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ private boolean storeInternal(final @NotNull SentryEnvelope envelope, final @Not
122122
try (final @NotNull ISentryLifecycleToken ignored = sessionLock.acquire()) {
123123
final @Nullable Session endingSession = readSessionFromEnvelope(envelope);
124124
final @Nullable Session currentSession = readSessionFromDisk(currentSessionFile);
125-
final boolean preservePendingSession =
125+
final boolean preserveCurrentSession =
126126
endingSession != null
127127
&& currentSession != null
128-
&& currentSession.isPendingUnhandled()
128+
&& currentSession.hasNonTerminatingUnhandledError()
129129
&& endingSession.getSessionId() != null
130130
&& currentSession.getSessionId() != null
131131
&& !Objects.equals(endingSession.getSessionId(), currentSession.getSessionId())
132132
&& endingSession.getStarted() != null
133133
&& currentSession.getStarted() != null
134134
&& currentSession.getStarted().after(endingSession.getStarted());
135-
if (!preservePendingSession && !currentSessionFile.delete()) {
135+
if (!preserveCurrentSession && !currentSessionFile.delete()) {
136136
options.getLogger().log(WARNING, "Current envelope doesn't exist.");
137137
}
138138
}
@@ -149,7 +149,7 @@ private boolean storeInternal(final @NotNull SentryEnvelope envelope, final @Not
149149
if (startingSession != null) {
150150
final @Nullable Session currentSession = readSessionFromDisk(currentSessionFile);
151151
if (currentSession != null && hasSameSessionId(currentSession, startingSession)) {
152-
if (!isNewerPendingOrErrorSnapshot(currentSession, startingSession)) {
152+
if (!isNewerUnhandledOrErrorSnapshot(currentSession, startingSession)) {
153153
writeSessionToDisk(currentSessionFile, startingSession);
154154
}
155155
} else {
@@ -355,9 +355,10 @@ private void writeCrashMarkerFile() {
355355
}
356356
}
357357

358-
private boolean isNewerPendingOrErrorSnapshot(
358+
private boolean isNewerUnhandledOrErrorSnapshot(
359359
final @NotNull Session currentSession, final @NotNull Session startingSession) {
360-
return (currentSession.isPendingUnhandled() && !startingSession.isPendingUnhandled())
360+
return (currentSession.hasNonTerminatingUnhandledError()
361+
&& !startingSession.hasNonTerminatingUnhandledError())
361362
|| currentSession.errorCount() > startingSession.errorCount();
362363
}
363364

‎sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ class EnvelopeCacheTest {
162162
}
163163

164164
@Test
165-
fun `delayed same SID SessionStart preserves newer pending snapshot`() {
165+
fun `delayed same SID SessionStart preserves newer unhandled snapshot`() {
166166
val cache = fixture.getSUT()
167167
val sid = SentryUUID.generateSentryId()
168168
val currentSessionFile = EnvelopeCache.getCurrentSessionFile(fixture.options.cacheDirPath!!)
169169
val previousSessionFile = EnvelopeCache.getPreviousSessionFile(fixture.options.cacheDirPath!!)
170170
val newerSession = createSession(sessionId = sid)
171-
newerSession.markPendingUnhandled()
171+
newerSession.recordNonTerminatingUnhandledError()
172172
cache.persistCurrentSession(newerSession)
173173

174174
val delayedStart = createSession(sessionId = sid)
@@ -181,7 +181,7 @@ class EnvelopeCacheTest {
181181
Session::class.java,
182182
)!!
183183
assertThat(persistedSession.sessionId).isEqualTo(sid)
184-
assertThat(persistedSession.isPendingUnhandled).isTrue()
184+
assertThat(persistedSession.hasNonTerminatingUnhandledError()).isTrue()
185185
assertThat(persistedSession.errorCount()).isEqualTo(1)
186186
assertThat(previousSessionFile.exists()).isFalse()
187187
}
@@ -206,7 +206,7 @@ class EnvelopeCacheTest {
206206
Session::class.java,
207207
)!!
208208
assertThat(persistedSession.sessionId).isEqualTo(sid)
209-
assertThat(persistedSession.isPendingUnhandled).isFalse()
209+
assertThat(persistedSession.hasNonTerminatingUnhandledError()).isFalse()
210210
assertThat(persistedSession.errorCount()).isEqualTo(1)
211211
assertThat(previousSessionFile.exists()).isFalse()
212212
}
@@ -280,11 +280,11 @@ class EnvelopeCacheTest {
280280
}
281281

282282
@Test
283-
fun `mismatching SessionEnd preserves newer pending current session`() {
283+
fun `mismatching SessionEnd preserves newer unhandled current session`() {
284284
val cache = fixture.getSUT()
285285
val endingSession = createSession(started = Date(1_000))
286286
val currentSession = createSession(started = Date(2_000))
287-
currentSession.markPendingUnhandled()
287+
currentSession.recordNonTerminatingUnhandledError()
288288
cache.persistCurrentSession(currentSession)
289289

290290
val envelope = SentryEnvelope.from(fixture.options.serializer, endingSession, null)
@@ -300,10 +300,10 @@ class EnvelopeCacheTest {
300300
}
301301

302302
@Test
303-
fun `mismatching newer SessionEnd deletes stale pending current session`() {
303+
fun `mismatching newer SessionEnd deletes stale unhandled current session`() {
304304
val cache = fixture.getSUT()
305305
val currentSession = createSession(started = Date(1_000))
306-
currentSession.markPendingUnhandled()
306+
currentSession.recordNonTerminatingUnhandledError()
307307
cache.persistCurrentSession(currentSession)
308308
val endingSession = createSession(started = Date(2_000))
309309

@@ -315,7 +315,7 @@ class EnvelopeCacheTest {
315315
}
316316

317317
@Test
318-
fun `mismatching SessionEnd deletes non-pending current session`() {
318+
fun `mismatching SessionEnd deletes current session without unhandled error`() {
319319
val cache = fixture.getSUT()
320320
val currentSession = createSession()
321321
cache.persistCurrentSession(currentSession)
@@ -555,11 +555,11 @@ class EnvelopeCacheTest {
555555
}
556556

557557
@Test
558-
fun `AbnormalExit hint keeps persisted pending session as abnormal`() {
558+
fun `AbnormalExit hint keeps persisted unhandled session as abnormal`() {
559559
val cache = fixture.getSUT()
560560

561561
val previousSessionFile = EnvelopeCache.getPreviousSessionFile(fixture.options.cacheDirPath!!)
562-
val session = createSession().apply { setPendingUnhandled(true) }
562+
val session = createSession().apply { setNonTerminatingUnhandledError(true) }
563563
fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
564564

565565
val envelope = SentryEnvelope.from(fixture.options.serializer, SentryEvent(), null)
@@ -581,7 +581,7 @@ class EnvelopeCacheTest {
581581
)
582582
assertEquals(State.Abnormal, updatedSession!!.status)
583583
assertEquals("abnormal_mechanism", updatedSession.abnormalMechanism)
584-
assertTrue(updatedSession.isPendingUnhandled)
584+
assertTrue(updatedSession.hasNonTerminatingUnhandledError())
585585
}
586586

587587
@Test
@@ -639,11 +639,11 @@ class EnvelopeCacheTest {
639639
}
640640

641641
@Test
642-
fun `NativeCrashExit hint keeps persisted pending session as crashed`() {
642+
fun `NativeCrashExit hint keeps persisted unhandled session as crashed`() {
643643
val cache = fixture.getSUT()
644644

645645
val previousSessionFile = EnvelopeCache.getPreviousSessionFile(fixture.options.cacheDirPath!!)
646-
val session = createSession().apply { setPendingUnhandled(true) }
646+
val session = createSession().apply { setNonTerminatingUnhandledError(true) }
647647
fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
648648

649649
val nativeCrashTimestamp = session.started!!.time + TimeUnit.HOURS.toMillis(1)
@@ -658,7 +658,7 @@ class EnvelopeCacheTest {
658658
)
659659
assertEquals(State.Crashed, updatedSession!!.status)
660660
assertEquals(nativeCrashTimestamp, updatedSession.timestamp!!.time)
661-
assertFalse(updatedSession.isPendingUnhandled)
661+
assertFalse(updatedSession.hasNonTerminatingUnhandledError())
662662
}
663663

664664
@Test

0 commit comments

Comments
 (0)