gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 02/04: improve error messages in DB transactions


From: gnunet
Subject: [taler-wallet-core] 02/04: improve error messages in DB transactions
Date: Mon, 12 Jul 2021 15:55:37 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

commit 2a48caa341716babb04caba9028ec8bf60021c5a
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Jul 12 15:54:25 2021 +0200

    improve error messages in DB transactions
---
 packages/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
index c7c08b47..b76bf6b6 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();

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]