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

chore: add error log for long storage requests [#WPB-11603] #3225

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlin.time.measureTime

sealed interface CoreFailure {

Expand Down Expand Up @@ -371,12 +372,20 @@ internal inline fun <T> wrapE2EIRequest(e2eiRequest: () -> T): Either<E2EIFailur
}

internal inline fun <T : Any> wrapStorageRequest(storageRequest: () -> T?): Either<StorageFailure, T> {
val result = try {
storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound)
} catch (e: Exception) {
Either.Left(StorageFailure.Generic(e))
val result: Either<StorageFailure, T>
measureTime {
result = try {
storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound)
} catch (e: Exception) {
Either.Left(StorageFailure.Generic(e))
}
result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}.run {
// Log error for requests longer than 1 second
if (inWholeSeconds > 1) {
kaliumLogger.e("storage request timeMs: $inWholeMilliseconds")
}
}
result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
return result
}

Expand Down
Loading