From a4603807e16b3055e4113f9a0b17cde5af275e0d Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 21 Jun 2018 12:01:11 -0700 Subject: [PATCH] Send/reply: Be resilient to errors making attachment thumbnail (#2468) * Show generic file icon if we fail to make attachment thumbnail * Be resilient to thumbnail creation errors when creating quote --- js/models/conversations.js | 18 +++++++++++++++--- js/views/file_input_view.js | 22 +++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 0fe7403a7096..b10635e8fd81 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -735,13 +735,25 @@ const willMakeThumbnail = Signal.Util.GoogleChrome.isImageTypeSupported(contentType) || Signal.Util.GoogleChrome.isVideoTypeSupported(contentType); + const makeThumbnail = async () => { + try { + if (willMakeThumbnail) { + return await this.makeThumbnailAttachment(attachment); + } + } catch (error) { + console.log( + 'Failed to create quote thumbnail', + error && error.stack ? error.stack : error + ); + } + + return null; + }; return { contentType, fileName: attachment.fileName, - thumbnail: willMakeThumbnail - ? await this.makeThumbnailAttachment(attachment) - : null, + thumbnail: makeThumbnail(), }; }) ), diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 3f4b9298abdc..bfdb2fb5e42e 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -274,13 +274,21 @@ this.addThumb(dataUrl); }; - if (Signal.Util.GoogleChrome.isImageTypeSupported(contentType)) { - renderImagePreview(); - } else if (Signal.Util.GoogleChrome.isVideoTypeSupported(contentType)) { - renderVideoPreview(); - } else if (MIME.isAudio(contentType)) { - this.addThumb('images/audio.svg'); - } else { + try { + if (Signal.Util.GoogleChrome.isImageTypeSupported(contentType)) { + await renderImagePreview(); + } else if (Signal.Util.GoogleChrome.isVideoTypeSupported(contentType)) { + await renderVideoPreview(); + } else if (MIME.isAudio(contentType)) { + this.addThumb('images/audio.svg'); + } else { + this.addThumb('images/file.svg'); + } + } catch (e) { + console.log( + `Was unable to generate thumbnail for file type ${contentType}`, + e && e.stack ? e.stack : e + ); this.addThumb('images/file.svg'); }