taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 2a48caa341716babb04caba9028ec8bf60021c5a
parent 0b854299d150aef448ec80943382e678699e418a
Author: Florian Dold <florian@dold.me>
Date:   Mon, 12 Jul 2021 15:54:25 +0200

improve error messages in DB transactions

Diffstat:
Mpackages/taler-wallet-core/src/util/query.ts | 21++++++++++++++++++---
1 file 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 @@ -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();