From fa593a7a37e8c77b11a1624bca9f78184ac5a04c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 21 Jun 2017 17:46:31 +0100 Subject: [PATCH] Treat errors when deleting indexeddb as non-fatal If we get an error when vaping the indexeddb, carry on regardless --- src/crypto/store/indexeddb-crypto-store.js | 8 ++++--- src/store/indexeddb-local-backend.js | 28 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/crypto/store/indexeddb-crypto-store.js b/src/crypto/store/indexeddb-crypto-store.js index 9e5e0d5aa..1c5b64dc6 100644 --- a/src/crypto/store/indexeddb-crypto-store.js +++ b/src/crypto/store/indexeddb-crypto-store.js @@ -116,9 +116,11 @@ export default class IndexedDBCryptoStore { }; req.onerror = (ev) => { - reject(new Error( - "unable to delete indexeddb: " + ev.target.error, - )); + // in firefox, with indexedDB disabled, this fails with a + // DOMError. We treat this as non-fatal, so that people can + // still use the app. + console.warn(`unable to delete IndexedDBCryptoStore: ${ev.target.error}`); + resolve(); }; req.onsuccess = () => { diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index 7f87c5739..5ee7cabb2 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -163,8 +163,32 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolved when the database is cleared. */ clearDatabase: function() { - console.log("Removing indexeddb instance: ", this._dbName); - return promiseifyRequest(this.indexedDB.deleteDatabase(this._dbName)); + return new q.Promise((resolve, reject) => { + console.log(`Removing indexeddb instance: ${this._dbName}`); + const req = this.indexedDB.deleteDatabase(this._dbName); + + req.onblocked = () => { + console.log( + `can't yet delete indexeddb ${this._dbName}` + + ` because it is open elsewhere`, + ); + }; + + req.onerror = (ev) => { + // in firefox, with indexedDB disabled, this fails with a + // DOMError. We treat this as non-fatal, so that we can still + // use the app. + console.warn( + `unable to delete js-sdk store indexeddb: ${ev.target.error}`, + ); + resolve(); + }; + + req.onsuccess = () => { + console.log(`Removed indexeddb instance: ${this._dbName}`); + resolve(); + }; + }); }, /**