From 0c05e974653aa7db53652d352d4ade94cb9b678d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 27 Aug 2021 19:07:27 +0200 Subject: [PATCH] abort upgrade txn on error --- src/matrix/storage/idb/utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/matrix/storage/idb/utils.js b/src/matrix/storage/idb/utils.js index fbb82fc5..b4e6209d 100644 --- a/src/matrix/storage/idb/utils.js +++ b/src/matrix/storage/idb/utils.js @@ -66,11 +66,18 @@ export function decodeUint32(str) { export function openDatabase(name, createObjectStore, version, idbFactory = window.indexedDB) { const req = idbFactory.open(name, version); - req.onupgradeneeded = (ev) => { + req.onupgradeneeded = async (ev) => { const db = ev.target.result; const txn = ev.target.transaction; const oldVersion = ev.oldVersion; - createObjectStore(db, txn, oldVersion, version); + try { + await createObjectStore(db, txn, oldVersion, version); + } catch (err) { + console.error("Aborting upgrade transaction because migration threw error"); + console.log(err.message); + console.log(err.stack); + txn.abort(); + } }; return reqAsPromise(req); }