abort upgrade txn on error

This commit is contained in:
Bruno Windels 2021-08-27 19:07:27 +02:00
parent a61f052fe8
commit 0c05e97465

View file

@ -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);
}