From e6a46874c40e0828b7882fd4d90f87e006e1d8d0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 21 Sep 2020 17:58:13 +0200 Subject: [PATCH] wrap olm error for creating session in DecryptionError so we can relate it back to the event that caused it --- src/matrix/e2ee/olm/Decryption.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/matrix/e2ee/olm/Decryption.js b/src/matrix/e2ee/olm/Decryption.js index fc16852a..a193e016 100644 --- a/src/matrix/e2ee/olm/Decryption.js +++ b/src/matrix/e2ee/olm/Decryption.js @@ -115,7 +115,12 @@ export class Decryption { } // could not decrypt with any existing session if (typeof plaintext !== "string" && isPreKeyMessage(message)) { - const createResult = this._createSessionAndDecrypt(senderKey, message, timestamp); + let createResult; + try { + createResult = this._createSessionAndDecrypt(senderKey, message, timestamp); + } catch (error) { + throw new DecryptionError(`Could not create inbound olm session: ${error.message}`, event, {senderKey, error}); + } senderKeyDecryption.addNewSession(createResult.session); plaintext = createResult.plaintext; } @@ -123,8 +128,8 @@ export class Decryption { let payload; try { payload = JSON.parse(plaintext); - } catch (err) { - throw new DecryptionError("PLAINTEXT_NOT_JSON", event, {plaintext, err}); + } catch (error) { + throw new DecryptionError("PLAINTEXT_NOT_JSON", event, {plaintext, error}); } this._validatePayload(payload, event); return new DecryptionResult(payload, senderKey, payload.keys);