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
This commit is contained in:
Eric Bailey
2025-05-27 13:25:41 -05:00
committed by GitHub
parent df2f62e94d
commit 342f820ec0
5 changed files with 45 additions and 13 deletions
+14 -1
View File
@@ -26,7 +26,13 @@ export type NotificationReason =
| 'chat-message' | 'chat-message'
| 'starterpack-joined' | 'starterpack-joined'
/**
* Manually overridden type, but retains the possibility of
* `notification.request.trigger.payload` being `undefined`, as specified in
* the source types.
*/
type NotificationPayload = type NotificationPayload =
| undefined
| { | {
reason: Exclude<NotificationReason, 'chat-message'> reason: Exclude<NotificationReason, 'chat-message'>
uri: string uri: string
@@ -47,7 +53,7 @@ const DEFAULT_HANDLER_OPTIONS = {
} satisfies Notifications.NotificationBehavior } satisfies Notifications.NotificationBehavior
// These need to stay outside the hook to persist between account switches // These need to stay outside the hook to persist between account switches
let storedPayload: NotificationPayload | undefined let storedPayload: NotificationPayload
let prevDate = 0 let prevDate = 0
const logger = Logger.create(Logger.Context.Notifications) const logger = Logger.create(Logger.Context.Notifications)
@@ -191,6 +197,11 @@ export function useNotificationsHandler() {
logger.debug('Notifications: received', {e}) logger.debug('Notifications: received', {e})
const payload = e.request.trigger.payload as NotificationPayload const payload = e.request.trigger.payload as NotificationPayload
if (!payload) {
return DEFAULT_HANDLER_OPTIONS
}
if ( if (
payload.reason === 'chat-message' && payload.reason === 'chat-message' &&
payload.recipientDid === currentAccount?.did payload.recipientDid === currentAccount?.did
@@ -231,6 +242,8 @@ export function useNotificationsHandler() {
const payload = e.notification.request.trigger const payload = e.notification.request.trigger
.payload as NotificationPayload .payload as NotificationPayload
if (!payload) return
logger.debug( logger.debug(
'User pressed a notification, opening notifications tab', 'User pressed a notification, opening notifications tab',
{}, {},
+11 -1
View File
@@ -27,5 +27,15 @@ init({
environment: process.env.NODE_ENV, environment: process.env.NODE_ENV,
dist, dist,
release, 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`,
],
}) })
+17 -8
View File
@@ -48,7 +48,7 @@ async function getGeolocation(): Promise<Device['geolocation']> {
/** /**
* Local promise used within this file only. * 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 * Begin the process of resolving geolocation. This should be called once at
@@ -65,12 +65,14 @@ export function beginResolveGeolocation() {
* and fail closed. * and fail closed.
*/ */
if (__DEV__) { if (__DEV__) {
geolocationResolution = new Promise(y => y()) geolocationResolution = new Promise(y => y({success: true}))
device.set(['geolocation'], DEFAULT_GEOLOCATION) device.set(['geolocation'], DEFAULT_GEOLOCATION)
return return
} }
geolocationResolution = new Promise(async resolve => { geolocationResolution = new Promise(async resolve => {
let success = true
try { try {
// Try once, fail fast // Try once, fail fast
const geolocation = await getGeolocation() const geolocation = await getGeolocation()
@@ -83,7 +85,9 @@ export function beginResolveGeolocation() {
throw new Error(`geolocation: nothing returned from initial request`) throw new Error(`geolocation: nothing returned from initial request`)
} }
} catch (e: any) { } catch (e: any) {
logger.error(`geolocation: failed initial request`, { success = false
logger.debug(`geolocation: failed initial request`, {
safeMessage: e.message, safeMessage: e.message,
}) })
@@ -97,6 +101,7 @@ export function beginResolveGeolocation() {
device.set(['geolocation'], geolocation) device.set(['geolocation'], geolocation)
emitGeolocationUpdate(geolocation) emitGeolocationUpdate(geolocation)
logger.debug(`geolocation: success`, {geolocation}) logger.debug(`geolocation: success`, {geolocation})
success = true
} else { } else {
// endpoint should throw on all failures, this is insurance // endpoint should throw on all failures, this is insurance
throw new Error(`geolocation: nothing returned from retries`) throw new Error(`geolocation: nothing returned from retries`)
@@ -107,7 +112,7 @@ export function beginResolveGeolocation() {
logger.debug(`geolocation: failed retries`, {safeMessage: e.message}) logger.debug(`geolocation: failed retries`, {safeMessage: e.message})
}) })
} finally { } finally {
resolve(undefined) resolve({success})
} }
}) })
} }
@@ -127,10 +132,14 @@ export async function ensureGeolocationResolved() {
logger.debug(`geolocation: using cache`, {cached}) logger.debug(`geolocation: using cache`, {cached})
} else { } else {
logger.debug(`geolocation: no cache`) logger.debug(`geolocation: no cache`)
await geolocationResolution const {success} = await geolocationResolution
logger.debug(`geolocation: resolved`, { if (success) {
resolved: device.get(['geolocation']), logger.debug(`geolocation: resolved`, {
}) resolved: device.get(['geolocation']),
})
} else {
logger.error(`geolocation: failed to resolve`)
}
} }
} }
+1 -1
View File
@@ -400,7 +400,7 @@ export const ComposePost = ({
).uris[0] ).uris[0]
try { try {
await whenAppViewReady(agent, postUri, res => { await whenAppViewReady(agent, postUri, res => {
const postedThread = res.data.thread const postedThread = res?.data?.thread
return AppBskyFeedDefs.isThreadViewPost(postedThread) return AppBskyFeedDefs.isThreadViewPost(postedThread)
}) })
} catch (waitErr: any) { } catch (waitErr: any) {
@@ -1,14 +1,14 @@
import {clearCache, createVideoThumbnail} from 'react-native-compressor' import {clearCache, createVideoThumbnail} from 'react-native-compressor'
import Animated, {FadeIn} from 'react-native-reanimated' import Animated, {FadeIn} from 'react-native-reanimated'
import {Image} from 'expo-image' 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' import {atoms as a} from '#/alf'
export const RQKEY = 'video-thumbnail' export const RQKEY = 'video-thumbnail'
export function clearThumbnailCache(queryClient: QueryClient) { export function clearThumbnailCache(queryClient: QueryClient) {
clearCache() clearCache().catch(() => {})
queryClient.resetQueries({queryKey: [RQKEY]}) queryClient.resetQueries({queryKey: [RQKEY]})
} }