From 8d18a4db5cac08370d78bc8f109bf64ced3d2419 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek <76782439+damian-kaczmarek@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:09:51 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=8D=92=20from=20develop=20-=20mo?= =?UTF-8?q?re=20logs=20sending=20message=20#WPB-11601?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wire/kalium/logic/CoreFailure.kt | 22 +++++++++++-------- .../logic/feature/message/MessageSender.kt | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt index 4ac76d5ae6b..24e28261290 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -21,6 +21,7 @@ package com.wire.kalium.logic import com.wire.kalium.cryptography.exceptions.ProteusException import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.functional.Either +import com.wire.kalium.logic.functional.onFailure import com.wire.kalium.network.exceptions.APINotSupported import com.wire.kalium.network.exceptions.KaliumException import com.wire.kalium.network.exceptions.isFederationDenied @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach sealed interface CoreFailure { @@ -368,12 +370,13 @@ internal inline fun wrapE2EIRequest(e2eiRequest: () -> T): Either wrapStorageRequest(storageRequest: () -> T?): Either { - return try { + val result = try { storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound) } catch (e: Exception) { - kaliumLogger.e(e.stackTraceToString()) Either.Left(StorageFailure.Generic(e)) } + result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } + return result } /** @@ -404,8 +407,9 @@ internal fun Flow.wrapStorageRequest(): Flow Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound) }.catch { e -> - kaliumLogger.e(e.stackTraceToString()) emit(Either.Left(StorageFailure.Generic(e))) + }.onEach { + it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } } internal inline fun wrapFlowStorageRequest(storageRequest: () -> Flow): Flow> { @@ -413,12 +417,12 @@ internal inline fun wrapFlowStorageRequest(storageRequest: () -> Flow< storageRequest().map { it?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound) }.catch { e -> - kaliumLogger.e(e.stackTraceToString()) emit(Either.Left(StorageFailure.Generic(e))) } } catch (e: Exception) { - kaliumLogger.e(e.stackTraceToString()) flowOf(Either.Left(StorageFailure.Generic(e))) + }.onEach { + it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } } } @@ -427,12 +431,12 @@ internal inline fun wrapNullableFlowStorageRequest(storageRequest: () storageRequest().map { Either.Right(it) as Either }.catch { e -> - kaliumLogger.e(e.stackTraceToString()) - emit(Either.Left(StorageFailure.Generic(e))) + emit(Either.Left(StorageFailure.Generic(e))) } } catch (e: Exception) { - kaliumLogger.e(e.stackTraceToString()) - flowOf(Either.Left(StorageFailure.Generic(e))) + flowOf(Either.Left(StorageFailure.Generic(e))) + }.onEach { + it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSender.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSender.kt index 9c6756126aa..4bfee8589f6 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSender.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSender.kt @@ -208,6 +208,8 @@ internal class MessageSenderImpl internal constructor( }.onSuccess { startSelfDeletionIfNeeded(message) } + }.onFailure { + logger.e("Failed to send message ${message::class.qualifiedName}. Failure = $it") } override suspend fun broadcastMessage(