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: 🍒 from develop - more logs sending message #WPB-11601 #3127

Merged
merged 1 commit into from
Nov 27, 2024
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
22 changes: 13 additions & 9 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -368,12 +370,13 @@ internal inline fun <T> wrapE2EIRequest(e2eiRequest: () -> T): Either<E2EIFailur
}

internal inline fun <T : Any> wrapStorageRequest(storageRequest: () -> T?): Either<StorageFailure, T> {
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
}

/**
Expand Down Expand Up @@ -404,21 +407,22 @@ internal fun <T : Any> Flow<T?>.wrapStorageRequest(): Flow<Either<StorageFailure
this.map {
it?.let { data -> Either.Right(data) } ?: Either.Left<StorageFailure>(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 <T : Any> wrapFlowStorageRequest(storageRequest: () -> Flow<T?>): Flow<Either<StorageFailure, T>> {
return try {
storageRequest().map {
it?.let { data -> Either.Right(data) } ?: Either.Left<StorageFailure>(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()) }
}
}

Expand All @@ -427,12 +431,12 @@ internal inline fun <T : Any> wrapNullableFlowStorageRequest(storageRequest: ()
storageRequest().map {
Either.Right(it) as Either<StorageFailure, T?>
}.catch { e ->
kaliumLogger.e(e.stackTraceToString())
emit(Either.Left(StorageFailure.Generic(e)))
emit(Either.Left<StorageFailure>(StorageFailure.Generic(e)))
}
} catch (e: Exception) {
kaliumLogger.e(e.stackTraceToString())
flowOf(Either.Left(StorageFailure.Generic(e)))
flowOf(Either.Left<StorageFailure>(StorageFailure.Generic(e)))
}.onEach {
it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading