Skip to content

Commit e597fa8

Browse files
IM.codesclaude
andcommitted
fix(push): log every silently swallowed error
Three silent catches in the push pipeline made today's APNS_KEY=12-char secret outage take hours to diagnose. Each one swallowed an exception without a single log line, leaving 78 server with "Relay 502" but the K8s pod logs completely empty: - push.ts relay route: importPKCS8() throw was caught and turned into a 502 JSON response with no log - bridge.ts dispatchEventPush: dynamic import failure (e.g. missing prod dep) silently disabled all push notifications - push.ts dispatchPush: badge_count UPDATE failure was a bare catch All three now log via the existing pino logger so the next failure surfaces immediately in `kubectl logs` instead of silently dropping notifications. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 785a810 commit e597fa8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

server/src/routes/push.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ pushRoutes.post('/relay', async (c) => {
9292
} catch (err) {
9393
const msg = err instanceof Error ? err.message : String(err);
9494
const unregistered = err instanceof PushError && err.unregistered;
95+
logger.warn(
96+
{ err, platform: body.platform, token: body.token.slice(0, 10) + '...', unregistered },
97+
'Push relay failed',
98+
);
9599
return c.json({ error: msg, unregistered }, unregistered ? 410 : 502);
96100
}
97101
});
@@ -145,7 +149,9 @@ export async function dispatchPush(payload: PushPayload, envOrDb: Env | Database
145149
[payload.userId],
146150
);
147151
if (rows.length > 0) badgeCount = rows[0].badge_count;
148-
} catch { /* fallback to 1 */ }
152+
} catch (err) {
153+
logger.warn({ err, userId: payload.userId }, 'Failed to increment badge_count — falling back to 1');
154+
}
149155
payload.badge = badgeCount;
150156

151157
const hasApns = !!(env.APNS_KEY && env.APNS_KEY_ID && env.APNS_TEAM_ID);

server/src/ws/bridge.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,10 @@ export class WsBridge {
21372137
const server = await db.queryOne<{ user_id: string; name: string }>('SELECT user_id, name FROM servers WHERE id = $1', [this.serverId]);
21382138
if (!server) return;
21392139

2140-
const { dispatchPush } = await import('../routes/push.js').catch(() => ({ dispatchPush: null }));
2140+
const { dispatchPush } = await import('../routes/push.js').catch((err) => {
2141+
logger.error({ err }, 'Failed to import push module — push notifications disabled');
2142+
return { dispatchPush: null };
2143+
});
21412144
if (!dispatchPush) return;
21422145

21432146
const sessionName = String(msg.session ?? msg.sessionId ?? '');

0 commit comments

Comments
 (0)