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:
Claude
2026-02-09 17:53:09 +00:00
parent 88012c69d1
commit 0cac0a1859
7 changed files with 48 additions and 10 deletions
+18 -4
View File
@@ -639,6 +639,8 @@ export const makeEventBuffer = (
if (updateId) {
newData.chatUpdates[updateId] = update
delete data.chatUpdates[updateId]
} else {
logger.debug({ update }, 'conditional chat update missing id, not carrying forward')
}
}
}
@@ -979,7 +981,10 @@ function append<E extends BufferableEvent>(
case 'chats.update':
for (const update of eventData as ChatUpdate[]) {
const chatId = update.id
if (!chatId) continue
if (!chatId) {
logger.debug({ update }, 'chats.update: update missing id, skipping')
continue
}
const conditionMatches = update.conditional ? update.conditional(data) : true
if (conditionMatches) {
delete update.conditional
@@ -1057,7 +1062,10 @@ function append<E extends BufferableEvent>(
const contactUpdates = eventData as BaileysEventMap['contacts.update']
for (const update of contactUpdates) {
const id = update.id
if (!id) continue
if (!id) {
logger.debug({ update }, 'contacts.update: update missing id, skipping')
continue
}
// merge into prior upsert
const upsert = data.historySets.contacts[id] || data.contactUpserts[id]
if (upsert) {
@@ -1179,7 +1187,10 @@ function append<E extends BufferableEvent>(
const groupUpdates = eventData as BaileysEventMap['groups.update']
for (const update of groupUpdates) {
const id = update.id
if (!id) continue
if (!id) {
logger.debug({ update }, 'groups.update: update missing id, skipping')
continue
}
const groupUpdate = data.groupUpdates[id] || {}
if (!data.groupUpdates[id]) {
data.groupUpdates[id] = Object.assign(groupUpdate, update)
@@ -1212,7 +1223,10 @@ function append<E extends BufferableEvent>(
// decrement chat unread counter
// if the message has already been marked read by us
const chatId = message.key.remoteJid
if (!chatId) return
if (!chatId) {
logger.debug({ messageKey: message.key }, 'decrementChatReadCounter: remoteJid missing, skipping')
return
}
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
if (
isRealMessage(message) &&
+4
View File
@@ -288,6 +288,7 @@ const processMessage = async (
) => {
const meUser = creds.me
if (!meUser) {
logger?.warn({ messageKey: message.key }, 'processMessage: creds.me not set, skipping message')
return
}
@@ -548,6 +549,7 @@ const processMessage = async (
} else if (content?.reactionMessage) {
const reactionKey = content.reactionMessage.key
if (!reactionKey) {
logger?.warn({ messageKey: message.key }, 'processMessage: reactionMessage.key missing, skipping')
return
}
@@ -565,6 +567,7 @@ const processMessage = async (
const encEventResponse = content.encEventResponseMessage
const creationMsgKey = encEventResponse.eventCreationMessageKey
if (!creationMsgKey) {
logger?.warn({ messageKey: message.key }, 'processMessage: eventCreationMessageKey missing, skipping')
return
}
@@ -580,6 +583,7 @@ const processMessage = async (
? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
: eventCreatorKey
if (!eventCreatorPn) {
logger?.warn({ messageKey: message.key, eventCreatorKey }, 'processMessage: eventCreatorPn missing, skipping')
return
}