From e41252b35e7d6fc14e5cef0ecc2b40e94eccf297 Mon Sep 17 00:00:00 2001 From: Alvaro <110414366+alvaro-signal@users.noreply.github.com> Date: Fri, 2 Dec 2022 18:05:27 -0700 Subject: [PATCH] Added clearer debug logging to createOrLookup --- ts/ConversationController.ts | 10 +++++++--- ts/SignalProtocolStore.ts | 2 ++ ts/background.ts | 5 +++++ ts/groups.ts | 1 + ts/messageModifiers/MessageRequests.ts | 1 + ts/messageModifiers/Reactions.ts | 2 ++ ts/messageModifiers/ReadSyncs.ts | 2 ++ ts/messageModifiers/ViewSyncs.ts | 2 ++ ts/messages/helpers.ts | 2 ++ ts/models/conversations.ts | 1 + ts/models/messages.ts | 3 +++ ts/services/storageRecordOps.ts | 12 +++++++++++- ts/state/smart/CallManager.tsx | 1 + ts/util/findStoryMessage.ts | 1 + ts/util/getProfile.ts | 1 + ts/util/handleRetry.ts | 1 + ts/util/lookupConversationWithoutUuid.ts | 1 + ts/util/markConversationRead.ts | 1 + ts/util/sendReceipts.ts | 1 + ts/util/sendToGroup.ts | 6 ++++++ ts/views/conversation_view.tsx | 3 +++ 21 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index 19ac69ba6813..e028a87c2993 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -642,15 +642,19 @@ export class ConversationController { lookupOrCreate({ e164, uuid, + reason, }: { e164?: string | null; uuid?: string | null; + reason: string; }): ConversationModel | undefined { const normalizedUuid = uuid ? uuid.toLowerCase() : undefined; const identifier = normalizedUuid || e164; if ((!e164 && !uuid) || !identifier) { - log.warn('lookupOrCreate: Called with neither e164 nor uuid!'); + log.warn( + `lookupOrCreate: Called with neither e164 nor uuid! reason: ${reason}` + ); return undefined; } @@ -684,7 +688,7 @@ export class ConversationController { // are truthy by this point. So we'll throw if that isn't the case. if (!convoE164 || !convoUuid) { throw new Error( - 'lookupOrCreate: convoE164 or convoUuid are falsey but should both be true!' + `lookupOrCreate: convoE164 or convoUuid are falsey but should both be true! reason: ${reason}` ); } @@ -695,7 +699,7 @@ export class ConversationController { // 5. If the two lookups disagree, log and return the UUID match log.warn( - `lookupOrCreate: Found a split contact - UUID ${normalizedUuid} and E164 ${e164}. Returning UUID match.` + `lookupOrCreate: Found a split contact - UUID ${normalizedUuid} and E164 ${e164}. Returning UUID match. reason: ${reason}` ); return convoUuid; } diff --git a/ts/SignalProtocolStore.ts b/ts/SignalProtocolStore.ts index c7feaae57498..06d9c01cebb7 100644 --- a/ts/SignalProtocolStore.ts +++ b/ts/SignalProtocolStore.ts @@ -1062,6 +1062,7 @@ export class SignalProtocolStore extends EventEmitter { const conversation = window.ConversationController.lookupOrCreate({ uuid: uuid.toString(), + reason: 'SignalProtocolStore.storeSession', }); strictAssert( conversation !== undefined, @@ -1393,6 +1394,7 @@ export class SignalProtocolStore extends EventEmitter { // First, fetch this conversation const conversation = window.ConversationController.lookupOrCreate({ uuid: uuid.toString(), + reason: 'SignalProtocolStore.lightSessionReset', }); assertDev(conversation, `lightSessionReset/${id}: missing conversation`); diff --git a/ts/background.ts b/ts/background.ts index f20c9837a61e..b5a30501e747 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2964,6 +2964,7 @@ export async function startApp(): Promise { const fromConversation = window.ConversationController.lookupOrCreate({ e164: data.source, uuid: data.sourceUuid, + reason: 'onMessageReceived:reaction', }); strictAssert(fromConversation, 'Reaction without fromConversation'); @@ -2997,6 +2998,7 @@ export async function startApp(): Promise { const fromConversation = window.ConversationController.lookupOrCreate({ e164: data.source, uuid: data.sourceUuid, + reason: 'onMessageReceived:delete', }); strictAssert(fromConversation, 'Delete missing fromConversation'); @@ -3113,6 +3115,7 @@ export async function startApp(): Promise { const conversation = window.ConversationController.lookupOrCreate({ uuid: destinationUuid, e164: destination, + reason: 'createSentMessage', }); if (!conversation || conversation.id === ourId) { return result; @@ -3742,6 +3745,7 @@ export async function startApp(): Promise { const senderConversation = window.ConversationController.lookupOrCreate({ e164: sender, uuid: senderUuid, + reason: 'onReadSync', }); const senderId = senderConversation?.id; @@ -3780,6 +3784,7 @@ export async function startApp(): Promise { const senderConversation = window.ConversationController.lookupOrCreate({ e164: senderE164, uuid: senderUuid, + reason: 'onViewSync', }); const senderId = senderConversation?.id; diff --git a/ts/groups.ts b/ts/groups.ts index 9996d1cbbe3c..da0cec0891bb 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -2498,6 +2498,7 @@ export function buildMigrationBubble( ].map(uuid => { const conversation = window.ConversationController.lookupOrCreate({ uuid, + reason: 'buildMigrationBubble', }); strictAssert(conversation, `Conversation not found for ${uuid}`); return conversation.id; diff --git a/ts/messageModifiers/MessageRequests.ts b/ts/messageModifiers/MessageRequests.ts index b26179094332..6c4aa86f19a7 100644 --- a/ts/messageModifiers/MessageRequests.ts +++ b/ts/messageModifiers/MessageRequests.ts @@ -107,6 +107,7 @@ export class MessageRequests extends Collection { conversation = window.ConversationController.lookupOrCreate({ e164: threadE164, uuid: threadUuid, + reason: 'MessageRequests.onResponse', }); } diff --git a/ts/messageModifiers/Reactions.ts b/ts/messageModifiers/Reactions.ts index 7bb6d5b2c9fd..adf57b66d1f1 100644 --- a/ts/messageModifiers/Reactions.ts +++ b/ts/messageModifiers/Reactions.ts @@ -48,6 +48,7 @@ export class Reactions extends Collection { const reactionsBySource = this.filter(re => { const targetSender = window.ConversationController.lookupOrCreate({ uuid: re.get('targetAuthorUuid'), + reason: 'Reactions.forMessage', }); const targetTimestamp = re.get('targetTimestamp'); return targetSender?.id === senderId && targetTimestamp === sentAt; @@ -92,6 +93,7 @@ export class Reactions extends Collection { const targetAuthorConversation = window.ConversationController.lookupOrCreate({ uuid: reaction.get('targetAuthorUuid'), + reason: 'Reactions.onReaction', }); const targetConversationId = targetAuthorConversation?.id; if (!targetConversationId) { diff --git a/ts/messageModifiers/ReadSyncs.ts b/ts/messageModifiers/ReadSyncs.ts index 58775e12fa49..9c18b293912b 100644 --- a/ts/messageModifiers/ReadSyncs.ts +++ b/ts/messageModifiers/ReadSyncs.ts @@ -62,6 +62,7 @@ export class ReadSyncs extends Collection { const sender = window.ConversationController.lookupOrCreate({ e164: message.get('source'), uuid: message.get('sourceUuid'), + reason: 'ReadSyncs.forMessage', }); const sync = this.find(item => { return ( @@ -88,6 +89,7 @@ export class ReadSyncs extends Collection { const sender = window.ConversationController.lookupOrCreate({ e164: item.source, uuid: item.sourceUuid, + reason: 'ReadSyncs.onSync', }); return isIncoming(item) && sender?.id === sync.get('senderId'); diff --git a/ts/messageModifiers/ViewSyncs.ts b/ts/messageModifiers/ViewSyncs.ts index 5743232b90e6..21838542a147 100644 --- a/ts/messageModifiers/ViewSyncs.ts +++ b/ts/messageModifiers/ViewSyncs.ts @@ -41,6 +41,7 @@ export class ViewSyncs extends Collection { const sender = window.ConversationController.lookupOrCreate({ e164: message.get('source'), uuid: message.get('sourceUuid'), + reason: 'ViewSyncs.forMessage', }); const syncs = this.filter(item => { return ( @@ -69,6 +70,7 @@ export class ViewSyncs extends Collection { const sender = window.ConversationController.lookupOrCreate({ e164: item.source, uuid: item.sourceUuid, + reason: 'ViewSyncs.onSync', }); return sender?.id === sync.get('senderId'); diff --git a/ts/messages/helpers.ts b/ts/messages/helpers.ts index 2ec3e404b5e0..e42015a3d100 100644 --- a/ts/messages/helpers.ts +++ b/ts/messages/helpers.ts @@ -121,6 +121,7 @@ export function isQuoteAMatch( const authorConversation = window.ConversationController.lookupOrCreate({ e164: 'author' in quote ? quote.author : undefined, uuid: authorUuid, + reason: 'helpers.isQuoteAMatch', }); return ( @@ -143,6 +144,7 @@ export function getContactId( const conversation = window.ConversationController.lookupOrCreate({ e164: source, uuid: sourceUuid, + reason: 'helpers.getContactId', }); return conversation?.id; } diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index acbcc9e79458..6e693210f9d7 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1354,6 +1354,7 @@ export class ConversationModel extends window.Backbone const source = window.ConversationController.lookupOrCreate({ uuid, e164, + reason: 'ConversationModel.onNewMessage', }); const typingToken = `${source?.id}.${sourceDevice}`; diff --git a/ts/models/messages.ts b/ts/models/messages.ts index e80aa8746ec0..74d873a9699d 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -395,6 +395,7 @@ export class MessageModel extends window.Backbone.Model { const conversation = window.ConversationController.lookupOrCreate({ e164: source, uuid: sourceUuid, + reason: 'MessageModel.getSenderIdentifier', })!; return `${conversation?.id}.${sourceDevice}-${sentAt}`; @@ -2458,6 +2459,7 @@ export class MessageModel extends window.Backbone.Model { const sender = window.ConversationController.lookupOrCreate({ e164: source, uuid: sourceUuid, + reason: 'handleDataMessage', })!; const hasGroupV2Prop = Boolean(initialMessage.groupV2); const isV1GroupUpdate = @@ -2959,6 +2961,7 @@ export class MessageModel extends window.Backbone.Model { const local = window.ConversationController.lookupOrCreate({ e164: source, uuid: sourceUuid, + reason: 'handleDataMessage:setProfileKey', }); local?.setProfileKey(profileKey); } diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index 703b5ec4a80b..df8c878e4ae5 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -1257,7 +1257,17 @@ export async function mergeAccountRecord( let conversation: ConversationModel | undefined; if (contact) { - conversation = window.ConversationController.lookupOrCreate(contact); + if (!contact.uuid && !contact.e164) { + log.error( + 'storageService.mergeAccountRecord: No uuid or e164 on contact' + ); + return undefined; + } + conversation = window.ConversationController.lookupOrCreate({ + uuid: contact.uuid, + e164: contact.e164, + reason: 'storageService.mergeAccountRecord', + }); } else if (legacyGroupId && legacyGroupId.length) { const groupId = Bytes.toBinary(legacyGroupId); conversation = window.ConversationController.get(groupId); diff --git a/ts/state/smart/CallManager.tsx b/ts/state/smart/CallManager.tsx index c8364636d060..38cc58242f59 100644 --- a/ts/state/smart/CallManager.tsx +++ b/ts/state/smart/CallManager.tsx @@ -124,6 +124,7 @@ const mapStateToActiveCallProp = ( >(uuid => { const convoForUuid = window.ConversationController.lookupOrCreate({ uuid, + reason: 'CallManager.mapStateToActiveCallProp', }); return convoForUuid ? conversationSelector(convoForUuid.id) : undefined; }); diff --git a/ts/util/findStoryMessage.ts b/ts/util/findStoryMessage.ts index 3badd967132f..2c64c67bb882 100644 --- a/ts/util/findStoryMessage.ts +++ b/ts/util/findStoryMessage.ts @@ -71,6 +71,7 @@ function isStoryAMatch( const authorConversation = window.ConversationController.lookupOrCreate({ e164: undefined, uuid: authorUuid, + reason: 'isStoryAMatch', }); return ( diff --git a/ts/util/getProfile.ts b/ts/util/getProfile.ts index 013d2be16efa..1765438fddd6 100644 --- a/ts/util/getProfile.ts +++ b/ts/util/getProfile.ts @@ -8,6 +8,7 @@ export async function getProfile(uuid?: string, e164?: string): Promise { const c = window.ConversationController.lookupOrCreate({ uuid, e164, + reason: 'getProfile', }); if (!c) { log.error('getProfile: failed to find conversation; doing nothing'); diff --git a/ts/util/handleRetry.ts b/ts/util/handleRetry.ts index 29b140029689..c104986fc883 100644 --- a/ts/util/handleRetry.ts +++ b/ts/util/handleRetry.ts @@ -729,6 +729,7 @@ function startAutomaticSessionReset(decryptionError: DecryptionErrorEventData) { const conversation = window.ConversationController.lookupOrCreate({ uuid: senderUuid, + reason: 'startAutomaticSessionReset', }); if (!conversation) { log.warn( diff --git a/ts/util/lookupConversationWithoutUuid.ts b/ts/util/lookupConversationWithoutUuid.ts index 825e0c75f180..cb9e5c2c5cf0 100644 --- a/ts/util/lookupConversationWithoutUuid.ts +++ b/ts/util/lookupConversationWithoutUuid.ts @@ -89,6 +89,7 @@ export async function lookupConversationWithoutUuid( if (foundUsername) { const convo = window.ConversationController.lookupOrCreate({ uuid: foundUsername.uuid, + reason: 'lookupConversationWithoutUuid', }); strictAssert(convo, 'We just ensured conversation existence'); diff --git a/ts/util/markConversationRead.ts b/ts/util/markConversationRead.ts index c5be57a7f5e9..065bc1f0c388 100644 --- a/ts/util/markConversationRead.ts +++ b/ts/util/markConversationRead.ts @@ -93,6 +93,7 @@ export async function markConversationRead( senderId: window.ConversationController.lookupOrCreate({ e164: messageSyncData.source, uuid: messageSyncData.sourceUuid, + reason: 'markConversationRead', })?.id, timestamp: messageSyncData.sent_at, isDirectConversation: isDirectConversation(conversationAttrs), diff --git a/ts/util/sendReceipts.ts b/ts/util/sendReceipts.ts index a9d76d898aec..417340c97f52 100644 --- a/ts/util/sendReceipts.ts +++ b/ts/util/sendReceipts.ts @@ -66,6 +66,7 @@ export async function sendReceipts({ const sender = window.ConversationController.lookupOrCreate({ e164: senderE164, uuid: senderUuid, + reason: 'sendReceipts', }); if (!sender) { throw new Error( diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index cd2ca2f88cb4..d9a54525d20d 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -1327,6 +1327,12 @@ async function fetchKeysForIdentifier( await markIdentifierUnregistered(identifier); return; } + log.error( + `fetchKeysForIdentifier: Error fetching ${ + devices || 'all' + } devices for ${identifier}`, + Errors.toLogFormat(error) + ); throw error; } } diff --git a/ts/views/conversation_view.tsx b/ts/views/conversation_view.tsx index db6cf393e60e..3efd2b69983b 100644 --- a/ts/views/conversation_view.tsx +++ b/ts/views/conversation_view.tsx @@ -1346,6 +1346,7 @@ export class ConversationView extends window.Backbone.View { window.ConversationController.lookupOrCreate({ uuid: message.sourceUuid, e164: message.source, + reason: 'conversation_view.showAllMedia', })?.id || message.conversationId, id: message.id, received_at: message.received_at, @@ -1824,6 +1825,7 @@ export class ConversationView extends window.Backbone.View { window.ConversationController.lookupOrCreate({ uuid: message.get('sourceUuid'), e164: message.get('source'), + reason: 'conversation_view.showLightBox', })?.id || message.get('conversationId'), received_at: message.get('received_at'), received_at_ms: Number(message.get('received_at_ms')), @@ -2122,6 +2124,7 @@ export class ConversationView extends window.Backbone.View { const conversation = window.ConversationController.lookupOrCreate({ e164, uuid, + reason: 'conversation_view.startConversation', }); strictAssert( conversation,