improve: clarify app state sync log when decryption key is unavailable
Changes the log message when an app-state-sync key is not found (404) to clearly indicate this is expected behavior for new sessions, not an error. Old encryption keys from previous sessions are not shared by the WhatsApp server to newly paired devices. Before: "failed to sync state from version" (looks like an error) After: "app state sync: decryption key not available for X -- expected for new sessions where old keys are not shared by the server" https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB
This commit is contained in:
+14
-5
@@ -638,14 +638,23 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
} catch (error: any) {
|
||||
// if retry attempts overshoot
|
||||
// or key not found
|
||||
const isKeyNotFound = error.output?.statusCode === 404
|
||||
const isIrrecoverableError =
|
||||
(attemptsMap[name] || 0) >= MAX_SYNC_ATTEMPTS ||
|
||||
error.output?.statusCode === 404 ||
|
||||
isKeyNotFound ||
|
||||
error.name === 'TypeError'
|
||||
logger.info(
|
||||
{ name, error: error.stack },
|
||||
`failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`
|
||||
)
|
||||
if (isKeyNotFound) {
|
||||
const currentVersion = states[name]?.version ?? 0
|
||||
logger.info(
|
||||
{ name },
|
||||
`app state sync: decryption key not available for "${name}" (syncing from v${currentVersion}) -- expected for new sessions where old keys are not shared by the server`
|
||||
)
|
||||
} else {
|
||||
logger.info(
|
||||
{ name, error: error.stack },
|
||||
`failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`
|
||||
)
|
||||
}
|
||||
await authState.keys.set({ 'app-state-sync-version': { [name]: null } })
|
||||
// increment number of retries
|
||||
attemptsMap[name] = (attemptsMap[name] || 0) + 1
|
||||
|
||||
Reference in New Issue
Block a user