From 70f26f914273efe1760f722b962e79b5224931af Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 9 Apr 2026 16:25:42 +0100 Subject: [PATCH] Separate cases in DeviceListener (#32973) * Separate cases in DeviceListener According to the comment in `else` there were two ways to end up there. Split these into separate cases and provide a different log message in each case. If we somehow get there another way, throw an error. * Replace a throw with an error log --- .../DeviceListenerCurrentDevice.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts index 7dbb976489..0460d82366 100644 --- a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts +++ b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts @@ -228,21 +228,25 @@ export class DeviceListenerCurrentDevice { logSpan.info("No default 4S key but backup disabled: no toast needed"); await this.setDeviceState("ok", logSpan); } - } else { - // If we get here, then we are verified, have key backup, and - // 4S, but allSystemsReady is false, which means that either - // secretStorageStatus.ready is false (which means that 4S - // doesn't have all the secrets), or we don't have the backup - // key cached locally. If any of the cross-signing keys are - // missing locally, that is handled by the - // `!allCrossSigningSecretsCached` branch above. - logSpan.warn("4S is missing secrets or backup key not cached", { + } else if (!recoveryIsOk) { + logSpan.warn("4S is missing secrets: setting state to KEY_STORAGE_OUT_OF_SYNC", { secretStorageStatus, allCrossSigningSecretsCached, isCurrentDeviceTrusted, keyBackupDownloadIsOk, }); await this.setDeviceState("key_storage_out_of_sync", logSpan); + } else if (!keyBackupDownloadIsOk) { + logSpan.warn("Backup key is not cached locally: setting state to KEY_STORAGE_OUT_OF_SYNC", { + secretStorageStatus, + allCrossSigningSecretsCached, + isCurrentDeviceTrusted, + keyBackupDownloadIsOk, + }); + await this.setDeviceState("key_storage_out_of_sync", logSpan); + } else { + // We should not get here + logSpan.error("DeviceListenerCurrentDevice: allSystemsReady was false, but no case matched."); } } }