From 67cb10fcaef7e859cf9348ebeb48bee8b9487f0a Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 16 Sep 2020 15:01:59 -0700 Subject: [PATCH] Ensure that ConversationController.load is resilient to errors --- js/models/messages.js | 32 ++++++++++++++++++++----------- ts/ConversationController.ts | 37 +++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index ca6fe7a74c..cb384f27a3 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1139,18 +1139,28 @@ const stickerData = this.get('sticker'); if (stickerData) { - const sticker = Signal.Stickers.getSticker( - stickerData.packId, - stickerData.stickerId - ); - const { emoji } = sticker || {}; - if (!emoji) { - window.log.warn('Unable to get emoji for sticker'); + try { + const sticker = Signal.Stickers.getSticker( + stickerData.packId, + stickerData.stickerId + ); + const { emoji } = sticker || {}; + if (!emoji) { + window.log.warn('Unable to get emoji for sticker'); + } + return { + text: i18n('message--getNotificationText--stickers'), + emoji, + }; + } catch (error) { + window.log.error( + 'getNotificationData: sticker fetch failed', + error && error.stack ? error.stack : error + ); + return { + text: i18n('message--getNotificationText--stickers'), + }; } - return { - text: i18n('message--getNotificationText--stickers'), - emoji, - }; } if (this.isCallHistory()) { diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index f12bcf0a45..2fcc26ce08 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -666,23 +666,30 @@ export class ConversationController { await Promise.all( this._conversations.map(async conversation => { - // This call is important to allow Conversation models not to generate their - // cached props on initial construction if we're in the middle of the load - // from the database. Then we come back to the models when it is safe and - // generate those props. - conversation.generateProps(); + try { + // This call is important to allow Conversation models not to generate their + // cached props on initial construction if we're in the middle of the load + // from the database. Then we come back to the models when it is safe and + // generate those props. + conversation.generateProps(); - if (!conversation.get('lastMessage')) { - await conversation.updateLastMessage(); - } + if (!conversation.get('lastMessage')) { + await conversation.updateLastMessage(); + } - // In case a too-large draft was saved to the database - const draft = conversation.get('draft'); - if (draft && draft.length > MAX_MESSAGE_BODY_LENGTH) { - conversation.set({ - draft: draft.slice(0, MAX_MESSAGE_BODY_LENGTH), - }); - updateConversation(conversation.attributes); + // In case a too-large draft was saved to the database + const draft = conversation.get('draft'); + if (draft && draft.length > MAX_MESSAGE_BODY_LENGTH) { + conversation.set({ + draft: draft.slice(0, MAX_MESSAGE_BODY_LENGTH), + }); + updateConversation(conversation.attributes); + } + } catch (error) { + window.log.error( + 'ConversationController.load/map: Failed to prepare a conversation', + error && error.stack ? error.stack : error + ); } }) );