From 67ace9692dfd056cac969d853496e196f7560e90 Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Wed, 19 Jun 2024 08:11:39 +0300 Subject: [PATCH] fix: Do not crash when adding a watchtower alert for a missing cipher item --- .../usecase/impl/WatchtowerSyncerImpl.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/impl/WatchtowerSyncerImpl.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/impl/WatchtowerSyncerImpl.kt index f8eaccdb..557cc413 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/impl/WatchtowerSyncerImpl.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/impl/WatchtowerSyncerImpl.kt @@ -145,14 +145,18 @@ private class WatchtowerClient( val results = processor.process(ciphers) db.transaction { results.forEach { r -> - db.watchtowerThreatQueries.upsert( - value = r.value, - threat = r.threat && !r.cipher.deleted, - cipherId = r.cipher.id, - type = type, - reportedAt = now, - version = version, - ) + // We might be inserting a threat report on a cipher that + // does not exist anymore. This is fine, just ignore it. + runCatching { + db.watchtowerThreatQueries.upsert( + value = r.value, + threat = r.threat && !r.cipher.deleted, + cipherId = r.cipher.id, + type = type, + reportedAt = now, + version = version, + ) + } } } }