Several async calls in the message loop and group queue are fire-and-forget without .catch() handlers. When WhatsApp disconnects or containers fail unexpectedly, these produce unhandled rejections that can crash the process. Add explicit .catch() at each call site so errors are logged with full context (groupJid, taskId) instead of crashing: - channel.setTyping() in message loop (adapted for channel abstraction) - startMessageLoop() in main() - runForGroup() and runTask() in group-queue (5 call sites) Closes #221 Co-authored-by: Naveen Jain <1779929+naveenspark@users.noreply.github.com> Co-authored-by: Skip Potter <skip.potter.va@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -370,7 +370,9 @@ async function startMessageLoop(): Promise<void> {
|
||||
messagesToSend[messagesToSend.length - 1].timestamp;
|
||||
saveState();
|
||||
// Show typing indicator while the container processes the piped message
|
||||
channel.setTyping?.(chatJid, true);
|
||||
channel.setTyping?.(chatJid, true)?.catch((err) =>
|
||||
logger.warn({ chatJid, err }, 'Failed to set typing indicator'),
|
||||
);
|
||||
} else {
|
||||
// No active container — enqueue for a new one
|
||||
queue.enqueueMessageCheck(chatJid);
|
||||
@@ -466,7 +468,10 @@ async function main(): Promise<void> {
|
||||
});
|
||||
queue.setProcessMessagesFn(processGroupMessages);
|
||||
recoverPendingMessages();
|
||||
startMessageLoop();
|
||||
startMessageLoop().catch((err) => {
|
||||
logger.fatal({ err }, 'Message loop crashed unexpectedly');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
// Guard: only run when executed directly, not when imported by tests
|
||||
|
||||
Reference in New Issue
Block a user