more information if migration failed, and pretty

This commit is contained in:
Sebastian 2023-01-12 15:50:36 -03:00
parent 473cbc3908
commit 72ca5ee8dd
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
2 changed files with 24 additions and 9 deletions

View File

@ -21,6 +21,7 @@ import {
Event,
IDBDatabase,
IDBFactory,
IDBObjectStore,
IDBTransaction,
} from "@gnu-taler/idb-bridge";
import {
@ -2477,20 +2478,35 @@ function upgradeFromStoreMap(
if (storeAddedVersion <= oldVersion) {
continue;
}
const s = db.createObjectStore(swi.storeName, {
autoIncrement: storeDesc.autoIncrement,
keyPath: storeDesc.keyPath,
});
let s: IDBObjectStore;
try {
s = db.createObjectStore(swi.storeName, {
autoIncrement: storeDesc.autoIncrement,
keyPath: storeDesc.keyPath,
});
} catch (e) {
const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : "";
throw Error(
`Migration failed. Could not create store ${swi.storeName}.${moreInfo}`,
);
}
for (const indexName in swi.indexMap as any) {
const indexDesc: IndexDescriptor = swi.indexMap[indexName];
const indexAddedVersion = indexDesc.versionAdded ?? 0;
if (indexAddedVersion <= oldVersion) {
continue;
}
s.createIndex(indexDesc.name, indexDesc.keyPath, {
multiEntry: indexDesc.multiEntry,
unique: indexDesc.unique,
});
try {
s.createIndex(indexDesc.name, indexDesc.keyPath, {
multiEntry: indexDesc.multiEntry,
unique: indexDesc.unique,
});
} catch (e) {
const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : "";
throw Error(
`Migration failed. Could not create index ${indexDesc.name}/${indexDesc.keyPath}.${moreInfo}`,
);
}
}
}
}

View File

@ -734,7 +734,6 @@ async function buildTransactionForPurchase(
checkDbInvariant(!!timestamp);
checkDbInvariant(!!purchaseRecord.payInfo);
let status: ExtendedStatus;
switch (purchaseRecord.purchaseStatus) {
case PurchaseStatus.AbortingWithRefund: