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, Event,
IDBDatabase, IDBDatabase,
IDBFactory, IDBFactory,
IDBObjectStore,
IDBTransaction, IDBTransaction,
} from "@gnu-taler/idb-bridge"; } from "@gnu-taler/idb-bridge";
import { import {
@ -2477,20 +2478,35 @@ function upgradeFromStoreMap(
if (storeAddedVersion <= oldVersion) { if (storeAddedVersion <= oldVersion) {
continue; continue;
} }
const s = db.createObjectStore(swi.storeName, { let s: IDBObjectStore;
autoIncrement: storeDesc.autoIncrement, try {
keyPath: storeDesc.keyPath, 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) { for (const indexName in swi.indexMap as any) {
const indexDesc: IndexDescriptor = swi.indexMap[indexName]; const indexDesc: IndexDescriptor = swi.indexMap[indexName];
const indexAddedVersion = indexDesc.versionAdded ?? 0; const indexAddedVersion = indexDesc.versionAdded ?? 0;
if (indexAddedVersion <= oldVersion) { if (indexAddedVersion <= oldVersion) {
continue; continue;
} }
s.createIndex(indexDesc.name, indexDesc.keyPath, { try {
multiEntry: indexDesc.multiEntry, s.createIndex(indexDesc.name, indexDesc.keyPath, {
unique: indexDesc.unique, 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(!!timestamp);
checkDbInvariant(!!purchaseRecord.payInfo); checkDbInvariant(!!purchaseRecord.payInfo);
let status: ExtendedStatus; let status: ExtendedStatus;
switch (purchaseRecord.purchaseStatus) { switch (purchaseRecord.purchaseStatus) {
case PurchaseStatus.AbortingWithRefund: case PurchaseStatus.AbortingWithRefund: