improve error reporting for DB queries

This commit is contained in:
Florian Dold 2020-03-12 13:22:46 +05:30
parent 2c52046f0b
commit 2ec6799c8c
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -218,7 +218,7 @@ class ResultStream<T> {
return { hasValue: false }; return { hasValue: false };
} }
if (!this.awaitingResult) { if (!this.awaitingResult) {
const cursor = this.req.result; const cursor: IDBCursor | undefined = this.req.result;
if (!cursor) { if (!cursor) {
throw Error("assertion failed"); throw Error("assertion failed");
} }
@ -330,7 +330,7 @@ function runWithTransaction<T>(
reject(TransactionAbort); reject(TransactionAbort);
}; };
const th = new TransactionHandle(tx); const th = new TransactionHandle(tx);
const resP = f(th); const resP = Promise.resolve().then(() => f(th));
resP resP
.then(result => { .then(result => {
gotFunResult = true; gotFunResult = true;
@ -340,10 +340,12 @@ function runWithTransaction<T>(
if (e == TransactionAbort) { if (e == TransactionAbort) {
console.info("aborting transaction"); console.info("aborting transaction");
} else { } else {
tx.abort();
console.error("Transaction failed:", e); console.error("Transaction failed:", e);
console.error(stack); console.error(stack);
tx.abort();
} }
}).catch((e) => {
console.error("fatal: aborting transaction failed", e);
}); });
}); });
} }