fix: skip restart recovery announcements when no channel is connected
Prevents web-dashboard-only startup from crashing when Discord channels are unavailable. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
56
src/index.ts
56
src/index.ts
@@ -174,6 +174,22 @@ export function _setRoomBindings(
|
|||||||
runtimeState.setRoomBindings(groups);
|
runtimeState.setRoomBindings(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function tryDeliverRestartAnnouncement(
|
||||||
|
chatJid: string,
|
||||||
|
rawText: string,
|
||||||
|
): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await deliverFormattedCanonicalMessage(chatJid, rawText);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn(
|
||||||
|
{ err, chatJid },
|
||||||
|
'Skipped restart recovery announcement because no channel is connected',
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function announceRestartRecovery(
|
async function announceRestartRecovery(
|
||||||
processStartedAtMs: number,
|
processStartedAtMs: number,
|
||||||
): Promise<RestartContext | null> {
|
): Promise<RestartContext | null> {
|
||||||
@@ -188,14 +204,17 @@ async function announceRestartRecovery(
|
|||||||
return explicitContext;
|
return explicitContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
await deliverFormattedCanonicalMessage(
|
if (
|
||||||
explicitContext.chatJid,
|
await tryDeliverRestartAnnouncement(
|
||||||
buildRestartAnnouncement(explicitContext),
|
explicitContext.chatJid,
|
||||||
);
|
buildRestartAnnouncement(explicitContext),
|
||||||
logger.info(
|
)
|
||||||
{ chatJid: explicitContext.chatJid },
|
) {
|
||||||
'Sent explicit restart recovery announcement',
|
logger.info(
|
||||||
);
|
{ chatJid: explicitContext.chatJid },
|
||||||
|
'Sent explicit restart recovery announcement',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const interrupted of getRecoverableInterruptedGroups(
|
for (const interrupted of getRecoverableInterruptedGroups(
|
||||||
explicitContext,
|
explicitContext,
|
||||||
@@ -204,7 +223,7 @@ async function announceRestartRecovery(
|
|||||||
if (hasRecentRestartAnnouncement(interrupted.chatJid, dedupeSince)) {
|
if (hasRecentRestartAnnouncement(interrupted.chatJid, dedupeSince)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await deliverFormattedCanonicalMessage(
|
await tryDeliverRestartAnnouncement(
|
||||||
interrupted.chatJid,
|
interrupted.chatJid,
|
||||||
buildInterruptedRestartAnnouncement(interrupted),
|
buildInterruptedRestartAnnouncement(interrupted),
|
||||||
);
|
);
|
||||||
@@ -226,14 +245,17 @@ async function announceRestartRecovery(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await deliverFormattedCanonicalMessage(
|
if (
|
||||||
inferred.chatJid,
|
await tryDeliverRestartAnnouncement(
|
||||||
inferred.lines.join('\n'),
|
inferred.chatJid,
|
||||||
);
|
inferred.lines.join('\n'),
|
||||||
logger.info(
|
)
|
||||||
{ chatJid: inferred.chatJid },
|
) {
|
||||||
'Sent inferred restart recovery announcement',
|
logger.info(
|
||||||
);
|
{ chatJid: inferred.chatJid },
|
||||||
|
'Sent inferred restart recovery announcement',
|
||||||
|
);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user