Couple of Sentry cleanups (#8532)

* Temp ignore a couple logs

* Add debug for unknown notifications

* Nvm let's do this in Sentry

* Downgrade two DMs network related issues

* Check for network errors before sending in Convo

* Do the same for event bus

* Fix mistake
This commit is contained in:
Eric Bailey
2025-06-20 11:30:52 -05:00
committed by GitHub
parent 4c75b568df
commit aeafb14fb4
3 changed files with 75 additions and 49 deletions
+13 -1
View File
@@ -322,7 +322,19 @@ export function useNotificationsHandler() {
const payload = e.notification.request.trigger const payload = e.notification.request.trigger
.payload as NotificationPayload .payload as NotificationPayload
if (!payload) return if (!payload) {
logger.error('useNotificationsHandler: received no payload', {
identifier: e.notification.request.identifier,
})
return
}
if (!payload.reason) {
logger.error('useNotificationsHandler: received unknown payload', {
payload,
identifier: e.notification.request.identifier,
})
return
}
logger.debug( logger.debug(
'User pressed a notification, opening notifications tab', 'User pressed a notification, opening notifications tab',
+44 -30
View File
@@ -10,6 +10,7 @@ import EventEmitter from 'eventemitter3'
import {nanoid} from 'nanoid/non-secure' import {nanoid} from 'nanoid/non-secure'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
import {isNetworkError} from '#/lib/strings/errors'
import {Logger} from '#/logger' import {Logger} from '#/logger'
import {isNative} from '#/platform/detection' import {isNative} from '#/platform/detection'
import { import {
@@ -130,7 +131,7 @@ export class Convo {
getSnapshot(): ConvoState { getSnapshot(): ConvoState {
if (!this.snapshot) this.snapshot = this.generateSnapshot() if (!this.snapshot) this.snapshot = this.generateSnapshot()
// logger.debug('Convo: snapshotted', {}) // logger.debug('snapshotted', {})
return this.snapshot return this.snapshot
} }
@@ -392,7 +393,7 @@ export class Convo {
break break
} }
logger.debug(`Convo: dispatch '${action.event}'`, { logger.debug(`dispatch '${action.event}'`, {
id: this.id, id: this.id,
prev: prevStatus, prev: prevStatus,
next: this.status, next: this.status,
@@ -467,13 +468,13 @@ export class Convo {
* Some validation prior to `Ready` status * Some validation prior to `Ready` status
*/ */
if (!this.convo) { if (!this.convo) {
throw new Error('Convo: could not find convo') throw new Error('could not find convo')
} }
if (!this.sender) { if (!this.sender) {
throw new Error('Convo: could not find sender in convo') throw new Error('could not find sender in convo')
} }
if (!this.recipients) { if (!this.recipients) {
throw new Error('Convo: could not find recipients in convo') throw new Error('could not find recipients in convo')
} }
const userIsDisabled = Boolean(this.sender.chatDisabled) const userIsDisabled = Boolean(this.sender.chatDisabled)
@@ -484,7 +485,11 @@ export class Convo {
this.dispatch({event: ConvoDispatchEvent.Ready}) this.dispatch({event: ConvoDispatchEvent.Ready})
} }
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: 'Convo: setup failed'}) if (!isNetworkError(e)) {
logger.error('setup failed', {
safeMessage: e.message,
})
}
this.dispatch({ this.dispatch({
event: ConvoDispatchEvent.Error, event: ConvoDispatchEvent.Error,
@@ -589,7 +594,11 @@ export class Convo {
this.sender = sender || this.sender this.sender = sender || this.sender
this.recipients = recipients || this.recipients this.recipients = recipients || this.recipients
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: `Convo: failed to refresh convo`}) if (!isNetworkError(e)) {
logger.error(`failed to refresh convo`, {
safeMessage: e.message,
})
}
} }
} }
@@ -599,7 +608,7 @@ export class Convo {
} }
| undefined | undefined
async fetchMessageHistory() { async fetchMessageHistory() {
logger.debug('Convo: fetch message history', {}) logger.debug('fetch message history', {})
/* /*
* If oldestRev is null, we've fetched all history. * If oldestRev is null, we've fetched all history.
@@ -653,7 +662,11 @@ export class Convo {
} }
} }
} catch (e: any) { } catch (e: any) {
logger.error('Convo: failed to fetch message history') if (!isNetworkError(e)) {
logger.error('failed to fetch message history', {
safeMessage: e.message,
})
}
this.fetchMessageHistoryError = { this.fetchMessageHistoryError = {
retry: () => { retry: () => {
@@ -802,7 +815,7 @@ export class Convo {
// Ignore empty messages for now since they have no other purpose atm // Ignore empty messages for now since they have no other purpose atm
if (!message.text.trim() && !message.embed) return if (!message.text.trim() && !message.embed) return
logger.debug('Convo: send message', {}) logger.debug('send message', {})
const tempId = nanoid() const tempId = nanoid()
@@ -836,7 +849,7 @@ export class Convo {
async processPendingMessages() { async processPendingMessages() {
logger.debug( logger.debug(
`Convo: processing messages (${this.pendingMessages.size} remaining)`, `processing messages (${this.pendingMessages.size} remaining)`,
{}, {},
) )
@@ -881,7 +894,6 @@ export class Convo {
// continue queue processing // continue queue processing
await this.processPendingMessages() await this.processPendingMessages()
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: `Convo: failed to send message`})
this.handleSendMessageFailure(e) this.handleSendMessageFailure(e)
this.isProcessingPendingMessages = false this.isProcessingPendingMessages = false
} }
@@ -914,21 +926,23 @@ export class Convo {
case 'recipient has disabled incoming messages': case 'recipient has disabled incoming messages':
break break
default: default:
logger.warn( if (!isNetworkError(e)) {
`Convo handleSendMessageFailure could not handle error`, logger.warn(`handleSendMessageFailure could not handle error`, {
{
status: e.status, status: e.status,
message: e.message, message: e.message,
}, })
) }
break break
} }
} }
} else { } else {
this.pendingMessageFailure = 'unrecoverable' this.pendingMessageFailure = 'unrecoverable'
logger.error(e, {
message: `Convo handleSendMessageFailure received unknown error`, if (!isNetworkError(e)) {
}) logger.error(`handleSendMessageFailure received unknown error`, {
safeMessage: e.message,
})
}
} }
this.commit() this.commit()
@@ -944,7 +958,7 @@ export class Convo {
this.commit() this.commit()
logger.debug( logger.debug(
`Convo: batch retrying ${this.pendingMessages.size} pending messages`, `batch retrying ${this.pendingMessages.size} pending messages`,
{}, {},
) )
@@ -977,18 +991,14 @@ export class Convo {
this.commit() this.commit()
logger.debug( logger.debug(`sent ${this.pendingMessages.size} pending messages`, {})
`Convo: sent ${this.pendingMessages.size} pending messages`,
{},
)
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: `Convo: failed to batch retry messages`})
this.handleSendMessageFailure(e) this.handleSendMessageFailure(e)
} }
} }
async deleteMessage(messageId: string) { async deleteMessage(messageId: string) {
logger.debug('Convo: delete message', {}) logger.debug('delete message', {})
this.deletedMessages.add(messageId) this.deletedMessages.add(messageId)
this.commit() this.commit()
@@ -1004,7 +1014,11 @@ export class Convo {
) )
}) })
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: `Convo: failed to delete message`}) if (!isNetworkError(e)) {
logger.error(`failed to delete message`, {
safeMessage: e.message,
})
}
this.deletedMessages.delete(messageId) this.deletedMessages.delete(messageId)
this.commit() this.commit()
throw e throw e
@@ -1232,7 +1246,7 @@ export class Convo {
} }
try { try {
logger.info(`Adding reaction ${emoji} to message ${messageId}`) logger.debug(`Adding reaction ${emoji} to message ${messageId}`)
const {data} = await this.agent.chat.bsky.convo.addReaction( const {data} = await this.agent.chat.bsky.convo.addReaction(
{messageId, value: emoji, convoId: this.convoId}, {messageId, value: emoji, convoId: this.convoId},
{encoding: 'application/json', headers: DM_SERVICE_HEADERS}, {encoding: 'application/json', headers: DM_SERVICE_HEADERS},
@@ -1297,7 +1311,7 @@ export class Convo {
} }
try { try {
logger.info(`Removing reaction ${emoji} from message ${messageId}`) logger.debug(`Removing reaction ${emoji} from message ${messageId}`)
await this.agent.chat.bsky.convo.removeReaction( await this.agent.chat.bsky.convo.removeReaction(
{messageId, value: emoji, convoId: this.convoId}, {messageId, value: emoji, convoId: this.convoId},
{encoding: 'application/json', headers: DM_SERVICE_HEADERS}, {encoding: 'application/json', headers: DM_SERVICE_HEADERS},
+18 -18
View File
@@ -3,6 +3,7 @@ import EventEmitter from 'eventemitter3'
import {nanoid} from 'nanoid/non-secure' import {nanoid} from 'nanoid/non-secure'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
import {isNetworkError} from '#/lib/strings/errors'
import {Logger} from '#/logger' import {Logger} from '#/logger'
import { import {
BACKGROUND_POLL_INTERVAL, BACKGROUND_POLL_INTERVAL,
@@ -18,7 +19,6 @@ import {
} from '#/state/messages/events/types' } from '#/state/messages/events/types'
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
const LOGGER_CONTEXT = 'MessagesEventBus'
const logger = Logger.create(Logger.Context.DMsAgent) const logger = Logger.create(Logger.Context.DMsAgent)
export class MessagesEventBus { export class MessagesEventBus {
@@ -91,17 +91,17 @@ export class MessagesEventBus {
} }
background() { background() {
logger.debug(`${LOGGER_CONTEXT}: background`, {}) logger.debug(`background`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Background}) this.dispatch({event: MessagesEventBusDispatchEvent.Background})
} }
suspend() { suspend() {
logger.debug(`${LOGGER_CONTEXT}: suspend`, {}) logger.debug(`suspend`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Suspend}) this.dispatch({event: MessagesEventBusDispatchEvent.Suspend})
} }
resume() { resume() {
logger.debug(`${LOGGER_CONTEXT}: resume`, {}) logger.debug(`resume`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Resume}) this.dispatch({event: MessagesEventBusDispatchEvent.Resume})
} }
@@ -228,7 +228,7 @@ export class MessagesEventBus {
break break
} }
logger.debug(`${LOGGER_CONTEXT}: dispatch '${action.event}'`, { logger.debug(`dispatch '${action.event}'`, {
id: this.id, id: this.id,
prev: prevStatus, prev: prevStatus,
next: this.status, next: this.status,
@@ -236,7 +236,7 @@ export class MessagesEventBus {
} }
private async init() { private async init() {
logger.debug(`${LOGGER_CONTEXT}: init`, {}) logger.debug(`init`, {})
try { try {
const response = await networkRetry(2, () => { const response = await networkRetry(2, () => {
@@ -260,9 +260,11 @@ export class MessagesEventBus {
this.dispatch({event: MessagesEventBusDispatchEvent.Ready}) this.dispatch({event: MessagesEventBusDispatchEvent.Ready})
} catch (e: any) { } catch (e: any) {
logger.error(e, { if (!isNetworkError(e)) {
message: `${LOGGER_CONTEXT}: init failed`, logger.error(`init failed`, {
}) safeMessage: e.message,
})
}
this.dispatch({ this.dispatch({
event: MessagesEventBusDispatchEvent.Error, event: MessagesEventBusDispatchEvent.Error,
@@ -324,7 +326,7 @@ export class MessagesEventBus {
this.isPolling = true this.isPolling = true
// logger.debug( // logger.debug(
// `${LOGGER_CONTEXT}: poll`, // `poll`,
// { // {
// requestedPollIntervals: Array.from( // requestedPollIntervals: Array.from(
// this.requestedPollIntervals.values(), // this.requestedPollIntervals.values(),
@@ -370,16 +372,14 @@ export class MessagesEventBus {
} }
if (needsEmit) { if (needsEmit) {
try { this.emitter.emit('event', {type: 'logs', logs: batch})
this.emitter.emit('event', {type: 'logs', logs: batch})
} catch (e: any) {
logger.error(e, {
message: `${LOGGER_CONTEXT}: process latest events`,
})
}
} }
} catch (e: any) { } catch (e: any) {
logger.error(e, {message: `${LOGGER_CONTEXT}: poll events failed`}) if (!isNetworkError(e)) {
logger.error(`poll events failed`, {
safeMessage: e.message,
})
}
this.dispatch({ this.dispatch({
event: MessagesEventBusDispatchEvent.Error, event: MessagesEventBusDispatchEvent.Error,