Skip to content

Commit 10b3eca

Browse files
committed
ComposeMenu: Give more specific Sentry error for unexpected library behavior
A skim through Sentry events matching the old error message suggests that we haven't yet had reports of firstAsset being present but with nullish `url` or `fileName`. But the types say they can be undefined, and we'll want to know if that's ever the case.
1 parent d74f46a commit 10b3eca

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/compose/ComposeMenu.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,32 @@ export default function ComposeMenu(props: Props): Node {
146146
// let `assets` have more than one item in `response`.
147147
const firstAsset = response.assets && response.assets[0];
148148

149-
const { uri, fileName } = firstAsset ?? {};
150-
151-
if (!firstAsset || uri == null || fileName == null) {
149+
if (!firstAsset) {
152150
// TODO: See if we these unexpected situations actually happen. …Ah,
153151
// yep, reportedly (and we've seen in Sentry):
154152
// https://github.com/react-native-image-picker/react-native-image-picker/issues/1945
155153
showErrorAlert(_('Error'), _('Failed to attach your file.'));
156-
logging.error('Unexpected response from image picker', {
157-
'!firstAsset': !firstAsset,
158-
'uri == null': uri == null,
159-
'fileName == null': fileName == null,
154+
logging.error('Image picker response gave falsy `assets` or falsy `assets[0]`', {
155+
'!assets': !response.assets,
160156
});
161157
return;
162158
}
163159

160+
const { uri, fileName } = firstAsset;
161+
162+
if (uri == null || fileName == null) {
163+
// TODO: See if these unexpected situations actually happen.
164+
showErrorAlert(_('Error'), _('Failed to attach your file.'));
165+
logging.error(
166+
'First (should be only) asset returned from image picker had nullish `url` and/or `fileName`',
167+
{
168+
'uri == null': uri == null,
169+
'fileName == null': fileName == null,
170+
},
171+
);
172+
return;
173+
}
174+
164175
insertAttachments([{ name: chooseUploadImageFilename(uri, fileName), url: uri }]);
165176
},
166177
[_, insertAttachments],

0 commit comments

Comments
 (0)