Log better errors when unable to show attachments

This commit is contained in:
Josh Perez 2022-04-29 14:48:26 -04:00 committed by GitHub
parent 6e7092c294
commit 4090e968b6
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];