From 6928c22477589ebddbe20573073f3de586dcd284 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 22 Jan 2025 16:28:16 -0500 Subject: [PATCH] Add some structured logging for backup import skips. --- .../securesms/backup/v2/ArchiveErrorCases.kt | 25 +++++++++++++++++++ .../v2/importer/ChatItemArchiveImporter.kt | 9 ++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt index b32bc21bb0..dbce857a73 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt @@ -114,3 +114,28 @@ object ExportOddities { return "[ODDITY][$sentTimestamp] $message" } } + +/** + * These represent situations where we will skip importing a data frame due to the data being invalid. + */ +object ImportSkips { + fun fromRecipientNotFound(sentTimestamp: Long): String { + return log(sentTimestamp, "Failed to find the fromRecipient for the message.") + } + + fun chatIdLocalRecipientNotFound(sentTimestamp: Long, chatId: Long): String { + return log(sentTimestamp, "Failed to find a local recipientId for the provided chatId. ChatId in backup: $chatId") + } + + fun chatIdRemoteRecipientNotFound(sentTimestamp: Long, chatId: Long): String { + return log(sentTimestamp, "Failed to find a remote recipientId for the provided chatId. ChatId in backup: $chatId") + } + + fun chatIdThreadNotFound(sentTimestamp: Long, chatId: Long): String { + return log(sentTimestamp, "Failed to find a threadId for the provided chatId. ChatId in backup: $chatId") + } + + private fun log(sentTimestamp: Long, message: String): String { + return "[SKIP][$sentTimestamp] $message" + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt index 58a29dd1bf..ec3c41f320 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt @@ -19,6 +19,7 @@ import org.signal.core.util.update import org.thoughtcrime.securesms.attachments.Attachment import org.thoughtcrime.securesms.attachments.PointerAttachment import org.thoughtcrime.securesms.attachments.TombstoneAttachment +import org.thoughtcrime.securesms.backup.v2.ImportSkips import org.thoughtcrime.securesms.backup.v2.ImportState import org.thoughtcrime.securesms.backup.v2.proto.BodyRange import org.thoughtcrime.securesms.backup.v2.proto.ChatItem @@ -158,25 +159,25 @@ class ChatItemArchiveImporter( fun import(chatItem: ChatItem) { val fromLocalRecipientId: RecipientId? = importState.remoteToLocalRecipientId[chatItem.authorId] if (fromLocalRecipientId == null) { - Log.w(TAG, "[insert] Could not find a local recipient for backup recipient ID ${chatItem.authorId}! Skipping.") + Log.w(TAG, ImportSkips.fromRecipientNotFound(chatItem.dateSent)) return } val chatLocalRecipientId: RecipientId? = importState.chatIdToLocalRecipientId[chatItem.chatId] if (chatLocalRecipientId == null) { - Log.w(TAG, "[insert] Could not find a local recipient for chatId ${chatItem.chatId}! Skipping.") + Log.w(TAG, ImportSkips.chatIdLocalRecipientNotFound(chatItem.dateSent, chatItem.chatId)) return } val localThreadId: Long? = importState.chatIdToLocalThreadId[chatItem.chatId] if (localThreadId == null) { - Log.w(TAG, "[insert] Could not find a local threadId for backup chatId ${chatItem.chatId}! Skipping.") + Log.w(TAG, ImportSkips.chatIdThreadNotFound(chatItem.dateSent, chatItem.chatId)) return } val chatBackupRecipientId: Long? = importState.chatIdToBackupRecipientId[chatItem.chatId] if (chatBackupRecipientId == null) { - Log.w(TAG, "[insert] Could not find a backup recipientId for backup chatId ${chatItem.chatId}! Skipping.") + Log.w(TAG, ImportSkips.chatIdRemoteRecipientNotFound(chatItem.dateSent, chatItem.chatId)) return } val messageInsert = chatItem.toMessageInsert(fromLocalRecipientId, chatLocalRecipientId, localThreadId)