From 73b2484e0863de3e7ea1e0fc8406a8b1469a5350 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 27 Mar 2019 15:48:38 +0000 Subject: [PATCH] Catch errors when checking IndexedDB In Firefox private browsing, we may get errors when checking storage consistency. We don't want that to block general Riot operation, so catch those errors and log instead. Fixes https://github.com/vector-im/riot-web/issues/9300 --- src/utils/StorageManager.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/utils/StorageManager.js b/src/utils/StorageManager.js index 5edb43fb0b..472e1c93d4 100644 --- a/src/utils/StorageManager.js +++ b/src/utils/StorageManager.js @@ -61,10 +61,16 @@ export async function checkConsistency() { } if (indexedDB && localStorage) { - const dataInSyncStore = await Matrix.IndexedDBStore.exists( - indexedDB, SYNC_STORE_NAME, - ); - log(`Sync store contains data? ${dataInSyncStore}`); + try { + const dataInSyncStore = await Matrix.IndexedDBStore.exists( + indexedDB, SYNC_STORE_NAME, + ); + log(`Sync store contains data? ${dataInSyncStore}`); + } catch (e) { + healthy = false; + error("Sync store inaccessible", e); + track("Sync store inaccessible"); + } } else { healthy = false; error("Sync store cannot be used on this browser"); @@ -72,10 +78,16 @@ export async function checkConsistency() { } if (indexedDB) { - dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists( - indexedDB, CRYPTO_STORE_NAME, - ); - log(`Crypto store contains data? ${dataInCryptoStore}`); + try { + dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists( + indexedDB, CRYPTO_STORE_NAME, + ); + log(`Crypto store contains data? ${dataInCryptoStore}`); + } catch (e) { + healthy = false; + error("Crypto store inaccessible", e); + track("Crypto store inaccessible"); + } } else { healthy = false; error("Crypto store cannot be used on this browser");