diff options
author | Eric Bailey <git@esb.lol> | 2025-05-27 13:25:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-27 13:25:41 -0500 |
commit | 342f820ec01fac0ff914175575bc7afe64fa71fd (patch) | |
tree | 6000b1192701409a53195ee12178aa0305759d95 /src | |
parent | df2f62e94ddee0b13ae48859617473f1905ec792 (diff) | |
download | voidsky-342f820ec01fac0ff914175575bc7afe64fa71fd.tar.zst |
Quiet some logs, fix a bug (#8404)
* Composer, 142k * Log geolocation error at most once per session * Clean thumb cache, 1.4m * Quiet generic network errors * Handle undefined notification payloads
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/hooks/useNotificationHandler.ts | 15 | ||||
-rw-r--r-- | src/logger/sentry/setup/index.ts | 12 | ||||
-rw-r--r-- | src/state/geolocation.tsx | 25 | ||||
-rw-r--r-- | src/view/com/composer/Composer.tsx | 2 | ||||
-rw-r--r-- | src/view/com/composer/videos/VideoTranscodeBackdrop.tsx | 4 |
5 files changed, 45 insertions, 13 deletions
diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index 9ddad7a16..f7cb6bae6 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -26,7 +26,13 @@ export type NotificationReason = | 'chat-message' | 'starterpack-joined' +/** + * Manually overridden type, but retains the possibility of + * `notification.request.trigger.payload` being `undefined`, as specified in + * the source types. + */ type NotificationPayload = + | undefined | { reason: Exclude<NotificationReason, 'chat-message'> uri: string @@ -47,7 +53,7 @@ const DEFAULT_HANDLER_OPTIONS = { } satisfies Notifications.NotificationBehavior // These need to stay outside the hook to persist between account switches -let storedPayload: NotificationPayload | undefined +let storedPayload: NotificationPayload let prevDate = 0 const logger = Logger.create(Logger.Context.Notifications) @@ -191,6 +197,11 @@ export function useNotificationsHandler() { logger.debug('Notifications: received', {e}) const payload = e.request.trigger.payload as NotificationPayload + + if (!payload) { + return DEFAULT_HANDLER_OPTIONS + } + if ( payload.reason === 'chat-message' && payload.recipientDid === currentAccount?.did @@ -231,6 +242,8 @@ export function useNotificationsHandler() { const payload = e.notification.request.trigger .payload as NotificationPayload + if (!payload) return + logger.debug( 'User pressed a notification, opening notifications tab', {}, diff --git a/src/logger/sentry/setup/index.ts b/src/logger/sentry/setup/index.ts index 6437d749a..3819211f3 100644 --- a/src/logger/sentry/setup/index.ts +++ b/src/logger/sentry/setup/index.ts @@ -27,5 +27,15 @@ init({ environment: process.env.NODE_ENV, dist, release, - ignoreErrors: [`t is not defined`, `Can't find variable: t`], + ignoreErrors: [ + /* + * Unknown internals errors + */ + `t is not defined`, + `Can't find variable: t`, + /* + * Un-useful errors + */ + `Network request failed`, + ], }) diff --git a/src/state/geolocation.tsx b/src/state/geolocation.tsx index 09b1b9471..83a42f21d 100644 --- a/src/state/geolocation.tsx +++ b/src/state/geolocation.tsx @@ -48,7 +48,7 @@ async function getGeolocation(): Promise<Device['geolocation']> { /** * Local promise used within this file only. */ -let geolocationResolution: Promise<void> | undefined +let geolocationResolution: Promise<{success: boolean}> | undefined /** * Begin the process of resolving geolocation. This should be called once at @@ -65,12 +65,14 @@ export function beginResolveGeolocation() { * and fail closed. */ if (__DEV__) { - geolocationResolution = new Promise(y => y()) + geolocationResolution = new Promise(y => y({success: true})) device.set(['geolocation'], DEFAULT_GEOLOCATION) return } geolocationResolution = new Promise(async resolve => { + let success = true + try { // Try once, fail fast const geolocation = await getGeolocation() @@ -83,7 +85,9 @@ export function beginResolveGeolocation() { throw new Error(`geolocation: nothing returned from initial request`) } } catch (e: any) { - logger.error(`geolocation: failed initial request`, { + success = false + + logger.debug(`geolocation: failed initial request`, { safeMessage: e.message, }) @@ -97,6 +101,7 @@ export function beginResolveGeolocation() { device.set(['geolocation'], geolocation) emitGeolocationUpdate(geolocation) logger.debug(`geolocation: success`, {geolocation}) + success = true } else { // endpoint should throw on all failures, this is insurance throw new Error(`geolocation: nothing returned from retries`) @@ -107,7 +112,7 @@ export function beginResolveGeolocation() { logger.debug(`geolocation: failed retries`, {safeMessage: e.message}) }) } finally { - resolve(undefined) + resolve({success}) } }) } @@ -127,10 +132,14 @@ export async function ensureGeolocationResolved() { logger.debug(`geolocation: using cache`, {cached}) } else { logger.debug(`geolocation: no cache`) - await geolocationResolution - logger.debug(`geolocation: resolved`, { - resolved: device.get(['geolocation']), - }) + const {success} = await geolocationResolution + if (success) { + logger.debug(`geolocation: resolved`, { + resolved: device.get(['geolocation']), + }) + } else { + logger.error(`geolocation: failed to resolve`) + } } } diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index e690e7256..42f057803 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -400,7 +400,7 @@ export const ComposePost = ({ ).uris[0] try { await whenAppViewReady(agent, postUri, res => { - const postedThread = res.data.thread + const postedThread = res?.data?.thread return AppBskyFeedDefs.isThreadViewPost(postedThread) }) } catch (waitErr: any) { diff --git a/src/view/com/composer/videos/VideoTranscodeBackdrop.tsx b/src/view/com/composer/videos/VideoTranscodeBackdrop.tsx index caf0b38e2..db38a76d9 100644 --- a/src/view/com/composer/videos/VideoTranscodeBackdrop.tsx +++ b/src/view/com/composer/videos/VideoTranscodeBackdrop.tsx @@ -1,14 +1,14 @@ import {clearCache, createVideoThumbnail} from 'react-native-compressor' import Animated, {FadeIn} from 'react-native-reanimated' import {Image} from 'expo-image' -import {QueryClient, useQuery} from '@tanstack/react-query' +import {type QueryClient, useQuery} from '@tanstack/react-query' import {atoms as a} from '#/alf' export const RQKEY = 'video-thumbnail' export function clearThumbnailCache(queryClient: QueryClient) { - clearCache() + clearCache().catch(() => {}) queryClient.resetQueries({queryKey: [RQKEY]}) } |