From b808a257a8e2a97d3b08e8ed0a56781e9dbe219d Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 9 Sep 2025 13:12:05 -0400 Subject: [PATCH] Ignore errors from importing secrets from secret storage --- .../matrix/api/encryption/RecoveryException.kt | 1 + .../matrix/impl/encryption/RecoveryExceptionMapper.kt | 3 +++ .../matrix/impl/encryption/RustEncryptionService.kt | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/RecoveryException.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/RecoveryException.kt index 70b335d4f94..33a2a89705c 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/RecoveryException.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/RecoveryException.kt @@ -10,6 +10,7 @@ package io.element.android.libraries.matrix.api.encryption import io.element.android.libraries.matrix.api.exception.ClientException sealed class RecoveryException(message: String) : Exception(message) { + class Import(message: String) : RecoveryException(message) class SecretStorage(message: String) : RecoveryException(message) data object BackupExistsOnServer : RecoveryException("BackupExistsOnServer") data class Client(val exception: ClientException) : RecoveryException(exception.message ?: "Unknown error") diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RecoveryExceptionMapper.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RecoveryExceptionMapper.kt index b9679eb1608..d98f3dd25fb 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RecoveryExceptionMapper.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RecoveryExceptionMapper.kt @@ -19,6 +19,9 @@ fun Throwable.mapRecoveryException(): RecoveryException { is RustRecoveryException.SecretStorage -> RecoveryException.SecretStorage( message = errorMessage ) + is RustRecoveryException.Import -> RecoveryException.Import( + message = errorMessage + ) is RustRecoveryException.BackupExistsOnServer -> RecoveryException.BackupExistsOnServer is RustRecoveryException.Client -> RecoveryException.Client( source.mapClientException() diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt index 7c87666fe7f..a5f0fd54121 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt @@ -44,6 +44,7 @@ import org.matrix.rustcomponents.sdk.UserIdentity import org.matrix.rustcomponents.sdk.BackupUploadState as RustBackupUploadState import org.matrix.rustcomponents.sdk.EnableRecoveryProgress as RustEnableRecoveryProgress import org.matrix.rustcomponents.sdk.SteadyStateException as RustSteadyStateException +import org.matrix.rustcomponents.sdk.RecoveryException as RustRecoveryException internal class RustEncryptionService( client: Client, @@ -182,8 +183,13 @@ internal class RustEncryptionService( override suspend fun recover(recoveryKey: String): Result = withContext(dispatchers.io) { runCatchingExceptions { service.recover(recoveryKey) - }.mapFailure { - it.mapRecoveryException() + }.recoverCatching { + if (it is RustRecoveryException.Import) { + // We ignore import errors because the user will be notified about them via the "Key storage out of sync" detection. + Unit + } else { + throw it.mapRecoveryException() + } } }