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'
| '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',
{},
+11 -1
View File
@@ -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`,
],
})
+17 -8
View File
@@ -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`)
}
}
}
+1 -1
View File
@@ -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) {
@@ -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]})
}