diff --git a/common/src/commonJvmAndroid/kotlin/com/wire/kalium/common/error/CoreCryptoExceptionMapper.kt b/common/src/commonJvmAndroid/kotlin/com/wire/kalium/common/error/CoreCryptoExceptionMapper.kt index 7321c8e06a..f8f6c9871e 100644 --- a/common/src/commonJvmAndroid/kotlin/com/wire/kalium/common/error/CoreCryptoExceptionMapper.kt +++ b/common/src/commonJvmAndroid/kotlin/com/wire/kalium/common/error/CoreCryptoExceptionMapper.kt @@ -32,8 +32,21 @@ actual fun mapMLSException(exception: Exception): MLSFailure = is MlsException.StaleCommit -> MLSFailure.StaleCommit is MlsException.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists is MlsException.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld - else -> MLSFailure.Generic(exception) + + is MlsException.Other -> { + if ((exception.v1 as MlsException.Other).v1 + .startsWith(COMMIT_FOR_MISSING_PROPOSAL) + ) { + MLSFailure.CommitForMissingProposal + } else { + MLSFailure.Other + } + } + + is MlsException.OrphanWelcome -> MLSFailure.Generic(exception) } } else { MLSFailure.Generic(exception) } + +private const val COMMIT_FOR_MISSING_PROPOSAL = "Incoming message is a commit for which we have not yet received all the proposals" diff --git a/common/src/commonMain/kotlin/com/wire/kalium/common/error/CoreFailure.kt b/common/src/commonMain/kotlin/com/wire/kalium/common/error/CoreFailure.kt index 09102801b9..d9ca8e3a3f 100644 --- a/common/src/commonMain/kotlin/com/wire/kalium/common/error/CoreFailure.kt +++ b/common/src/commonMain/kotlin/com/wire/kalium/common/error/CoreFailure.kt @@ -181,7 +181,7 @@ sealed class NetworkFailure : CoreFailure { data object FeatureNotSupported : NetworkFailure() } -interface MLSFailure : CoreFailure { +sealed interface MLSFailure : CoreFailure { data object WrongEpoch : MLSFailure @@ -200,10 +200,9 @@ interface MLSFailure : CoreFailure { data object StaleCommit : MLSFailure data object InternalErrors : MLSFailure data object Disabled : MLSFailure - - data class Generic(val exception: Exception) : MLSFailure { - val rootCause: Throwable get() = exception - } + data object Other : MLSFailure + data object CommitForMissingProposal : MLSFailure + data class Generic(val rootCause: Throwable) : MLSFailure } interface E2EIFailure : CoreFailure { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 740c801d00..1c60403987 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -40,7 +40,7 @@ pbandk = "0.15.0" turbine = "1.1.0" avs = "10.0.5" jna = "5.14.0" -core-crypto = "3.0.2" +core-crypto = "3.1.0" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.1.3" diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt index abb9f1b8d7..fc102ef366 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt @@ -18,7 +18,11 @@ package com.wire.kalium.logic.sync.receiver.conversation.message import com.wire.kalium.common.error.CoreFailure +import com.wire.kalium.common.error.E2EIFailure import com.wire.kalium.common.error.MLSFailure +import com.wire.kalium.common.error.NetworkFailure +import com.wire.kalium.common.error.ProteusFailure +import com.wire.kalium.common.error.StorageFailure sealed class MLSMessageFailureResolution { data object Ignore : MLSMessageFailureResolution() @@ -31,20 +35,45 @@ internal object MLSMessageFailureHandler { return when (failure) { // Received messages targeting a future epoch (outside epoch bounds), we might have lost messages. is MLSFailure.WrongEpoch -> MLSMessageFailureResolution.OutOfSync + // Received already sent or received message, can safely be ignored. - is MLSFailure.DuplicateMessage -> MLSMessageFailureResolution.Ignore - // Received message was targeting a future epoch and been buffered, can safely be ignored. - is MLSFailure.BufferedFutureMessage -> MLSMessageFailureResolution.Ignore - // Received self commit, any unmerged group has know been when merged by CoreCrypto. - is MLSFailure.SelfCommitIgnored -> MLSMessageFailureResolution.Ignore - // Message arrive in an unmerged group, it has been buffered and will be consumed later. - is MLSFailure.UnmergedPendingGroup -> MLSMessageFailureResolution.Ignore - is MLSFailure.StaleProposal -> MLSMessageFailureResolution.Ignore - is MLSFailure.StaleCommit -> MLSMessageFailureResolution.Ignore - is MLSFailure.MessageEpochTooOld -> MLSMessageFailureResolution.Ignore - is MLSFailure.InternalErrors -> MLSMessageFailureResolution.Ignore - is MLSFailure.Disabled -> MLSMessageFailureResolution.Ignore - else -> MLSMessageFailureResolution.InformUser + is MLSFailure.DuplicateMessage, + // Received message was targeting a future epoch and been buffered, can safely be ignored. + is MLSFailure.BufferedFutureMessage, + // Received self commit, any unmerged group has know been when merged by CoreCrypto. + is MLSFailure.SelfCommitIgnored, + // Message arrive in an unmerged group, it has been buffered and will be consumed later. + is MLSFailure.UnmergedPendingGroup, + is MLSFailure.StaleProposal, + is MLSFailure.StaleCommit, + is MLSFailure.MessageEpochTooOld, + is MLSFailure.InternalErrors, + is MLSFailure.Disabled, + MLSFailure.CommitForMissingProposal, + is CoreFailure.DevelopmentAPINotAllowedOnProduction -> MLSMessageFailureResolution.Ignore + + MLSFailure.ConversationAlreadyExists, + MLSFailure.ConversationDoesNotSupportMLS, + is MLSFailure.Generic, + is MLSFailure.Other, + is E2EIFailure, + is CoreFailure.FeatureFailure, + CoreFailure.MissingClientRegistration, + is CoreFailure.MissingKeyPackages, + NetworkFailure.FeatureNotSupported, + is NetworkFailure.FederatedBackendFailure.ConflictingBackends, + is NetworkFailure.FederatedBackendFailure.FailedDomains, + is NetworkFailure.FederatedBackendFailure.FederationDenied, + is NetworkFailure.FederatedBackendFailure.FederationNotEnabled, + is NetworkFailure.FederatedBackendFailure.General, + is NetworkFailure.NoNetworkConnection, + is NetworkFailure.ProxyError, + is NetworkFailure.ServerMiscommunication, + is ProteusFailure, + StorageFailure.DataNotFound, + is StorageFailure.Generic, + is CoreFailure.Unknown -> MLSMessageFailureResolution.InformUser + } } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt index 96e35e3972..4eda0a64cf 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt @@ -575,7 +575,7 @@ class ConversationGroupRepositoryTest { conversationGroupRepository.addService(serviceID, TestConversation.ID) .shouldFail { assertIs(it) - assertIs(it.exception) + assertIs(it.rootCause) } coVerify {