Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech/sync error logging #262

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ class CrashTrackerLogger : ErrorTracker {
override fun track(throwable: Throwable, extra: String) {
Log.e("ST", throwable.message, throwable)
log(AppLogTag.ERROR_NON_FATAL, "${throwable.message ?: "N/A"} extra=$extra")

throwable.findCauseMessage()?.let {
if (throwable.message != it) {
log(AppLogTag.ERROR_NON_FATAL, it)
}
}
}
}

private fun Throwable.findCauseMessage(): String? {
return when (val inner = this.cause) {
null -> this.message ?: ""
else -> inner.findCauseMessage()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import app.dapk.st.profile.state.ProfileState
import app.dapk.st.viewmodel.DapkViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -58,11 +57,10 @@ internal class HomeViewModel(

private suspend fun initialHomeContent(): SignedIn {
val me = chatEngine.me(forceRefresh = false)
val initialInvites = chatEngine.invites().first().size
return when (val current = state) {
Loading -> SignedIn(Page.Directory, me, invites = initialInvites)
is SignedIn -> current.copy(me = me, invites = initialInvites)
SignedOut -> SignedIn(Page.Directory, me, invites = initialInvites)
Loading -> SignedIn(Page.Directory, me, invites = 0)
is SignedIn -> current.copy(me = me, invites = current.invites)
SignedOut -> SignedIn(Page.Directory, me, invites = 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ private fun Events(selectedPageContent: SelectedState, onExit: () -> Unit, onSel
null -> "${it.time}: ${it.tag}: ${it.content}"
else -> "${it.time}: ${it.content}"
}

Text(
text = text,
modifier = Modifier.padding(horizontal = 4.dp),
lineHeight = 14.sp,
modifier = Modifier.padding(horizontal = 4.dp).fillMaxWidth(),
fontSize = 10.sp,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class DefaultSyncService(
)
SyncUseCase(
overviewStore,
SideEffectFlowIterator(logger),
SideEffectFlowIterator(logger, errorTracker),
SyncSideEffects(keySharer, verificationHandler, deviceNotifier, messageDecrypter, json, oneTimeKeyProducer, logger),
httpClient,
syncStore,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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) {
internal class SideEffectFlowIterator(private val logger: MatrixLogger, private val errorTracker: ErrorTracker) {
suspend fun <T> loop(initial: T?, onPost: suspend () -> Unit, onIteration: suspend (T?) -> T?) {
var previousState = initial

Expand All @@ -18,7 +19,7 @@ internal class SideEffectFlowIterator(private val logger: MatrixLogger) {
onPost()
} catch (error: Throwable) {
logger.matrixLog(SYNC, "on loop error: ${error.message}")
error.printStackTrace()
errorTracker.track(error, "sync loop error")
delay(10000L)
}
}
Expand Down