From 974771b4ed9272c841638f93d032b23d2689da1b Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 19 Jul 2023 10:23:08 -0400 Subject: [PATCH] Log when OlmMachine returns unexpected value Also condense the validity checks on the returned value --- src/e2ee/CryptoClient.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/e2ee/CryptoClient.ts b/src/e2ee/CryptoClient.ts index 0f6d8f63..a70aae4d 100644 --- a/src/e2ee/CryptoClient.ts +++ b/src/e2ee/CryptoClient.ts @@ -169,13 +169,12 @@ export class CryptoClient { await this.engine.lock.acquire(SYNC_LOCK_NAME, async () => { const syncResp = JSON.parse(await this.engine.machine.receiveSyncChanges(deviceMessages, deviceLists, otkCounts, unusedFallbackKeyAlgs)); - if (Array.isArray(syncResp)) { - const decryptedToDeviceMessages = syncResp[0]; - if (Array.isArray(decryptedToDeviceMessages)) { - for (const msg of decryptedToDeviceMessages as IToDeviceMessage[]) { - this.client.emit("to_device.decrypted", msg); - } + if (Array.isArray(syncResp) && syncResp.length === 2 && Array.isArray(syncResp[0])) { + for (const msg of syncResp[0] as IToDeviceMessage[]) { + this.client.emit("to_device.decrypted", msg); } + } else { + LogService.error("CryptoClient", "OlmMachine.receiveSyncChanges did not return an expected value of [to-device events, room key changes]"); } await this.engine.run();