summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-07-12 15:54:25 +0200
committerFlorian Dold <florian@dold.me>2021-07-12 15:54:25 +0200
commit2a48caa341716babb04caba9028ec8bf60021c5a (patch)
tree94f2fa8c458fc982da404ce020d9d0dbccc990f0 /packages/taler-wallet-core/src/util
parent0b854299d150aef448ec80943382e678699e418a (diff)
downloadwallet-core-2a48caa341716babb04caba9028ec8bf60021c5a.tar.gz
wallet-core-2a48caa341716babb04caba9028ec8bf60021c5a.tar.bz2
wallet-core-2a48caa341716babb04caba9028ec8bf60021c5a.zip
improve error messages in DB transactions
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/query.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts
index c7c08b47c..b76bf6b6b 100644
--- a/packages/taler-wallet-core/src/util/query.ts
+++ b/packages/taler-wallet-core/src/util/query.ts
@@ -87,6 +87,15 @@ interface CursorValueResult<T> {
value: T;
}
+class TransactionAbortedError extends Error {
+ constructor(m: string) {
+ super(m);
+
+ // Set the prototype explicitly.
+ Object.setPrototypeOf(this, TransactionAbortedError.prototype);
+ }
+}
+
class ResultStream<T> {
private currentPromise: Promise<void>;
private gotCursorEnd = false;
@@ -396,6 +405,7 @@ function runTx<Arg, Res>(
return new Promise((resolve, reject) => {
let funResult: any = undefined;
let gotFunResult = false;
+ let transactionException: any = undefined;
tx.oncomplete = () => {
// This is a fatal error: The transaction completed *before*
// the transaction function returned. Likely, the transaction
@@ -416,12 +426,16 @@ function runTx<Arg, Res>(
logger.error(`${stack}`);
};
tx.onabort = () => {
+ let msg: string;
if (tx.error) {
- logger.error("Transaction aborted with error:", tx.error);
+ msg = `Transaction aborted (transaction error): ${tx.error}`;
+ } else if (transactionException !== undefined) {
+ msg = `Transaction aborted (exception thrown): ${transactionException}`;
} else {
- logger.error("Transaction aborted (no error)");
+ msg = "Transaction aborted (no DB error)";
}
- reject(TransactionAbort);
+ logger.error(msg);
+ reject(new TransactionAbortedError(msg));
};
const resP = Promise.resolve().then(() => f(arg));
resP
@@ -433,6 +447,7 @@ function runTx<Arg, Res>(
if (e == TransactionAbort) {
logger.trace("aborting transaction");
} else {
+ transactionException = e;
console.error("Transaction failed:", e);
console.error(stack);
tx.abort();