fix(messages-recv): plain ack and error handling on early-ignore path
Addresses Codex P1 + Copilot + CodeRabbit review on PR #383: 1. Use plain sendMessageAck(node) for ignored messages — InfiniteAPI's prior in-handler check did NOT use NACK_REASONS.UnhandledError. The error code reports a processing failure and can trigger server-side retries; ignored stanzas are an intentional drop, not a failure. Restoring the original semantics. 2. Wrap the early-ignore block in try/catch routing to onUnexpectedError. shouldIgnoreJid is a user-provided callback and sendMessageAck can throw (e.g. websocket closed). Without this guard, the error becomes an unhandled promise rejection because the early path runs outside processNodeWithBuffer's catch wrapper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3091,7 +3091,12 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
// Fast path: ack and drop ignored JIDs before entering the buffer/queue.
|
||||
// Skips type='call' so call events are never silently dropped via
|
||||
// shouldIgnoreJid (preserves InfiniteAPI's pre-existing behavior).
|
||||
// Wrapped in try/catch so a throw from shouldIgnoreJid (user callback)
|
||||
// or sendMessageAck (e.g. websocket closed) is routed through
|
||||
// onUnexpectedError instead of becoming an unhandled rejection —
|
||||
// matches the protection processNodeWithBuffer provides.
|
||||
if (type !== 'call') {
|
||||
try {
|
||||
const from = node.attrs.from
|
||||
let ignoreJid = from
|
||||
if (type === 'receipt' && from) {
|
||||
@@ -3105,7 +3110,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (ignoreJid && ignoreJid !== S_WHATSAPP_NET && shouldIgnoreJid(ignoreJid)) {
|
||||
await sendMessageAck(node, type === 'message' ? NACK_REASONS.UnhandledError : undefined)
|
||||
// Plain ack (no NACK error code) preserves InfiniteAPI's prior
|
||||
// behavior — ignored stanzas are an intentional drop, not a
|
||||
// processing failure, so we don't want server-side retries.
|
||||
await sendMessageAck(node)
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
onUnexpectedError(error as Error, identifier)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user