From b8f60d804a242cdaecc6c98b5c72fa79dcd80bfc Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 10 Nov 2022 22:37:08 +0000 Subject: [PATCH] tracking and logging locally sync errors --- .../dapk/st/matrix/sync/internal/DefaultSyncService.kt | 2 +- .../app/dapk/st/matrix/sync/internal/FlowIterator.kt | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/DefaultSyncService.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/DefaultSyncService.kt index 13a9076..1d92479 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/DefaultSyncService.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/DefaultSyncService.kt @@ -76,7 +76,7 @@ internal class DefaultSyncService( ) SyncUseCase( overviewStore, - SideEffectFlowIterator(logger), + SideEffectFlowIterator(logger, errorTracker), SyncSideEffects(keySharer, verificationHandler, deviceNotifier, messageDecrypter, json, oneTimeKeyProducer, logger), httpClient, syncStore, diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/FlowIterator.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/FlowIterator.kt index 16a6a3b..71e5208 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/FlowIterator.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/FlowIterator.kt @@ -1,12 +1,13 @@ package app.dapk.st.matrix.sync.internal +import app.dapk.st.core.extensions.ErrorTracker import app.dapk.st.matrix.common.MatrixLogTag.SYNC import app.dapk.st.matrix.common.MatrixLogger import app.dapk.st.matrix.common.matrixLog import kotlinx.coroutines.* -internal class SideEffectFlowIterator(private val logger: MatrixLogger) { - suspend fun loop(initial: T?, onPost: suspend () -> Unit, onIteration: suspend (T?) -> T?) { +internal class SideEffectFlowIterator(private val logger: MatrixLogger, private val errorTracker: ErrorTracker) { + suspend fun loop(initial: T?, onPost: suspend (Throwable?) -> Unit, onIteration: suspend (T?) -> T?) { var previousState = initial while (currentCoroutineContext().isActive) { @@ -15,11 +16,12 @@ internal class SideEffectFlowIterator(private val logger: MatrixLogger) { previousState = withContext(NonCancellable) { onIteration(previousState) } - onPost() + onPost(null) } catch (error: Throwable) { logger.matrixLog(SYNC, "on loop error: ${error.message}") - error.printStackTrace() + errorTracker.track(error, "sync loop error") delay(10000L) + onPost(error) } } logger.matrixLog(SYNC, "isActive: ${currentCoroutineContext().isActive}")