improve: add warning logs to null guards and fix transferDevice error handling
- Add warning/debug logs to all null guard patterns (if (!x) return/continue) so that when these guards fire, the reason is visible in logs instead of being silently swallowed - Fix jid-utils.ts transferDevice: throw Error instead of returning empty string '' which could propagate as an invalid JID - process-message.ts: warn on creds.me missing, reactionKey missing, creationMsgKey missing, eventCreatorPn missing - chats.ts: warn on sendPresenceUpdate/handlePresenceUpdate missing values - event-buffer.ts: debug on chat/contact/group update missing id - socket.ts: debug on sessionStartTime not set - communities.ts: debug on dirty node not found - libsignal.ts: warn on bulk migration jidDecode failure https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB
This commit is contained in:
+22
-5
@@ -754,9 +754,16 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (!toJid) return
|
||||
if (!toJid) {
|
||||
logger.warn('sendPresenceUpdate: toJid is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
const decoded = jidDecode(toJid)
|
||||
if (!decoded) return
|
||||
if (!decoded) {
|
||||
logger.warn({ toJid }, 'sendPresenceUpdate: failed to decode toJid, skipping')
|
||||
return
|
||||
}
|
||||
const { server } = decoded
|
||||
const isLid = server === 'lid'
|
||||
|
||||
@@ -798,7 +805,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
let presence: PresenceData | undefined
|
||||
const jid = attrs.from
|
||||
const participant = attrs.participant || attrs.from
|
||||
if (!jid) return
|
||||
if (!jid) {
|
||||
logger.warn({ attrs }, 'handlePresenceUpdate: jid (attrs.from) is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
|
||||
return
|
||||
@@ -811,7 +821,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
} else if (Array.isArray(content)) {
|
||||
const [firstChild] = content
|
||||
if (!firstChild) return
|
||||
if (!firstChild) {
|
||||
logger.warn({ jid }, 'handlePresenceUpdate: firstChild content is empty, skipping')
|
||||
return
|
||||
}
|
||||
let type = firstChild.tag as WAPresence
|
||||
if (type === 'paused') {
|
||||
type = 'available'
|
||||
@@ -827,7 +840,11 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (presence) {
|
||||
if (!participant) return
|
||||
if (!participant) {
|
||||
logger.warn({ jid }, 'handlePresenceUpdate: participant is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ export const makeCommunitiesSocket = (config: SocketConfig) => {
|
||||
sock.ws.on('CB:ib,,dirty', async (node: BinaryNode) => {
|
||||
const dirtyNode = getBinaryNodeChild(node, 'dirty')
|
||||
if (!dirtyNode) {
|
||||
logger.debug({ node: node.tag }, 'community dirty handler: no dirty node found, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -886,6 +886,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (!sessionStartTime) {
|
||||
logger.debug('TTL timer: sessionStartTime not set, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user