File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
sentry-android-replay/src
main/java/io/sentry/android/replay
test/java/io/sentry/android/replay Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public class ReplayCache(
5555 internal val frames = mutableListOf<ReplayFrame >()
5656
5757 private val ongoingSegment = LinkedHashMap <String , String >()
58- private val ongoingSegmentFile: File ? by lazy {
58+ internal val ongoingSegmentFile: File ? by lazy {
5959 if (replayCacheDir == null ) {
6060 return @lazy null
6161 }
@@ -275,6 +275,9 @@ public class ReplayCache(
275275 if (isClosed.get()) {
276276 return
277277 }
278+ if (ongoingSegmentFile?.exists() != true ) {
279+ ongoingSegmentFile?.createNewFile()
280+ }
278281 if (ongoingSegment.isEmpty()) {
279282 ongoingSegmentFile?.useLines { lines ->
280283 lines.associateTo(ongoingSegment) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import android.view.MotionEvent
55import io.sentry.Breadcrumb
66import io.sentry.DateUtils
77import io.sentry.IScopes
8+ import io.sentry.SentryLevel.ERROR
89import io.sentry.SentryOptions
910import io.sentry.SentryReplayEvent.ReplayType
1011import io.sentry.SentryReplayEvent.ReplayType.BUFFER
@@ -183,7 +184,11 @@ internal abstract class BaseCaptureStrategy(
183184 task()
184185 }
185186 } else {
186- task()
187+ try {
188+ task()
189+ } catch (e: Throwable ) {
190+ options.logger.log(ERROR , " Failed to execute task $TAG .runInBackground" , e)
191+ }
187192 }
188193 }
189194
Original file line number Diff line number Diff line change @@ -285,6 +285,21 @@ class ReplayCacheTest {
285285 assertFalse(File (replayCache.replayCacheDir, ONGOING_SEGMENT ).exists())
286286 }
287287
288+ @Test
289+ fun `when file does not exist upon persisting creates it` () {
290+ val replayId = SentryId ()
291+ val replayCache = fixture.getSut(
292+ tmpDir,
293+ replayId
294+ )
295+
296+ replayCache.ongoingSegmentFile?.delete()
297+
298+ replayCache.persistSegmentValues(" key" , " value" )
299+ val segmentValues = File (replayCache.replayCacheDir, ONGOING_SEGMENT ).readLines()
300+ assertEquals(" key=value" , segmentValues[0 ])
301+ }
302+
288303 @Test
289304 fun `stores segment key value pairs` () {
290305 val replayId = SentryId ()
You can’t perform that action at this time.
0 commit comments