+12
src/lib/strings/errors.ts
+12
src/lib/strings/errors.ts
···
52
const str = String(e)
53
return str.includes('Bad token scope') || str.includes('Bad token method')
54
}
55
+
56
+
/**
57
+
* Intended to capture "User cancelled" or "Crop cancelled" errors
58
+
* that we often get from expo modules such expo-image-crop-tool
59
+
*
60
+
* The exact name has changed in the past so let's just see if the string
61
+
* contains "cancel"
62
+
*/
63
+
export function isCancelledError(e: unknown) {
64
+
const str = String(e).toLowerCase()
65
+
return str.includes('cancel')
66
+
}
+13
-5
src/screens/Onboarding/StepProfile/index.tsx
+13
-5
src/screens/Onboarding/StepProfile/index.tsx
···
15
import {getDataUriSize} from '#/lib/media/util'
16
import {useRequestNotificationsPermission} from '#/lib/notifications/notifications'
17
import {logEvent, useGate} from '#/lib/statsig/statsig'
18
import {isNative, isWeb} from '#/platform/detection'
19
import {
20
DescriptionText,
···
184
if (!image) return
185
186
if (!isWeb) {
187
-
image = await openCropper({
188
-
imageUri: image.path,
189
-
shape: 'circle',
190
-
aspectRatio: 1 / 1,
191
-
})
192
}
193
image = await compressIfNeeded(image, 1000000)
194
···
15
import {getDataUriSize} from '#/lib/media/util'
16
import {useRequestNotificationsPermission} from '#/lib/notifications/notifications'
17
import {logEvent, useGate} from '#/lib/statsig/statsig'
18
+
import {isCancelledError} from '#/lib/strings/errors'
19
+
import {logger} from '#/logger'
20
import {isNative, isWeb} from '#/platform/detection'
21
import {
22
DescriptionText,
···
186
if (!image) return
187
188
if (!isWeb) {
189
+
try {
190
+
image = await openCropper({
191
+
imageUri: image.path,
192
+
shape: 'circle',
193
+
aspectRatio: 1 / 1,
194
+
})
195
+
} catch (e) {
196
+
if (!isCancelledError(e)) {
197
+
logger.error('Failed to crop avatar in onboarding', {error: e})
198
+
}
199
+
}
200
}
201
image = await compressIfNeeded(image, 1000000)
202
+2
-1
src/state/gallery.ts
+2
-1
src/state/gallery.ts
···
17
import {openCropper} from '#/lib/media/picker'
18
import {type PickerImage} from '#/lib/media/picker.shared'
19
import {getDataUriSize} from '#/lib/media/util'
20
import {isNative} from '#/platform/detection'
21
22
export type ImageTransformation = {
···
143
},
144
}
145
} catch (e) {
146
-
if (e instanceof Error && e.message.includes('User cancelled')) {
147
return img
148
}
149
···
17
import {openCropper} from '#/lib/media/picker'
18
import {type PickerImage} from '#/lib/media/picker.shared'
19
import {getDataUriSize} from '#/lib/media/util'
20
+
import {isCancelledError} from '#/lib/strings/errors'
21
import {isNative} from '#/platform/detection'
22
23
export type ImageTransformation = {
···
144
},
145
}
146
} catch (e) {
147
+
if (!isCancelledError(e)) {
148
return img
149
}
150
+4
-3
src/view/com/util/UserAvatar.tsx
+4
-3
src/view/com/util/UserAvatar.tsx
···
26
import {type PickerImage} from '#/lib/media/picker.shared'
27
import {makeProfileLink} from '#/lib/routes/links'
28
import {sanitizeDisplayName} from '#/lib/strings/display-names'
29
import {sanitizeHandle} from '#/lib/strings/handles'
30
import {logger} from '#/logger'
31
import {isAndroid, isNative, isWeb} from '#/platform/detection'
···
407
setRawImage(await createComposerImage(item))
408
editImageDialogControl.open()
409
}
410
-
} catch (e: any) {
411
// Don't log errors for cancelling selection to sentry on ios or android
412
-
if (!String(e).toLowerCase().includes('cancel')) {
413
-
logger.error('Failed to crop banner', {error: e})
414
}
415
}
416
}, [
···
26
import {type PickerImage} from '#/lib/media/picker.shared'
27
import {makeProfileLink} from '#/lib/routes/links'
28
import {sanitizeDisplayName} from '#/lib/strings/display-names'
29
+
import {isCancelledError} from '#/lib/strings/errors'
30
import {sanitizeHandle} from '#/lib/strings/handles'
31
import {logger} from '#/logger'
32
import {isAndroid, isNative, isWeb} from '#/platform/detection'
···
408
setRawImage(await createComposerImage(item))
409
editImageDialogControl.open()
410
}
411
+
} catch (e) {
412
// Don't log errors for cancelling selection to sentry on ios or android
413
+
if (!isCancelledError(e)) {
414
+
logger.error('Failed to crop avatar', {error: e})
415
}
416
}
417
}, [
+4
-2
src/view/com/util/UserBanner.tsx
+4
-2
src/view/com/util/UserBanner.tsx
···
12
import {compressIfNeeded} from '#/lib/media/manip'
13
import {openCamera, openCropper, openPicker} from '#/lib/media/picker'
14
import {type PickerImage} from '#/lib/media/picker.shared'
15
import {logger} from '#/logger'
16
import {isAndroid, isNative} from '#/platform/detection'
17
import {
···
87
setRawImage(await createComposerImage(items[0]))
88
editImageDialogControl.open()
89
}
90
-
} catch (e: any) {
91
-
if (!String(e).includes('Canceled')) {
92
logger.error('Failed to crop banner', {error: e})
93
}
94
}
···
12
import {compressIfNeeded} from '#/lib/media/manip'
13
import {openCamera, openCropper, openPicker} from '#/lib/media/picker'
14
import {type PickerImage} from '#/lib/media/picker.shared'
15
+
import {isCancelledError} from '#/lib/strings/errors'
16
import {logger} from '#/logger'
17
import {isAndroid, isNative} from '#/platform/detection'
18
import {
···
88
setRawImage(await createComposerImage(items[0]))
89
editImageDialogControl.open()
90
}
91
+
} catch (e) {
92
+
// Don't log errors for cancelling selection to sentry on ios or android
93
+
if (!isCancelledError(e)) {
94
logger.error('Failed to crop banner', {error: e})
95
}
96
}