Skip to content

Commit

Permalink
Log better errors when unable to show attachments
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and josh-signal committed Apr 29, 2022
1 parent f235d48 commit 8dd2a1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ts/test-both/types/errors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
6 changes: 6 additions & 0 deletions ts/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions ts/views/conversation_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 8dd2a1a

Please sign in to comment.