Add some structured logging for backup import skips.

This commit is contained in:
Greyson Parrelli 2025-01-22 16:28:16 -05:00
parent 577b445bf8
commit 6928c22477
2 changed files with 30 additions and 4 deletions

View file

@ -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"
}
}

View file

@ -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)