Log better errors when unable to show attachments

Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2022-04-29 12:34:46 -07:00 committed by GitHub
parent f235d48e99
commit 8dd2a1a467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -29,7 +29,7 @@ describe('Errors', () => {
assert.isUndefined(error.stack);
const formattedError = Errors.toLogFormat(error);
assert.strictEqual(formattedError, 'Error: boom');
assert.strictEqual(formattedError, 'boom');
});
[0, false, null, undefined].forEach(value => {

View File

@ -3,11 +3,17 @@
/* eslint-disable max-classes-per-file */
import { get, has } from 'lodash';
export function toLogFormat(error: unknown): string {
if (error instanceof Error && error.stack) {
return error.stack;
}
if (has(error, 'message')) {
return get(error, 'message');
}
return String(error);
}

View File

@ -2138,6 +2138,21 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
getAbsoluteAttachmentPath(item.thumbnail?.path ?? ''),
}));
if (!media.length) {
log.error(
'showLightbox: unable to load attachment',
attachments.map(x => ({
contentType: x.contentType,
error: x.error,
flags: x.flags,
path: x.path,
size: x.size,
}))
);
showToast(ToastUnableToLoadAttachment);
return;
}
const selectedMedia =
media.find(item => attachment.path === item.path) || media[0];