gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: add more info when wallet-cor


From: gnunet
Subject: [taler-wallet-core] branch master updated: add more info when wallet-core is not available
Date: Mon, 12 Feb 2024 20:06:38 +0100

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 86194c614 add more info when wallet-core is not available
86194c614 is described below

commit 86194c61457f2e2e534cd05071bde9633e205ad3
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Feb 12 15:54:49 2024 -0300

    add more info when wallet-core is not available
---
 packages/taler-util/src/logging.ts                 | 24 +++++++++++++++++++++-
 packages/taler-wallet-core/src/db.ts               |  6 +++++-
 packages/taler-wallet-core/src/host-impl.node.ts   |  6 +++++-
 .../taler-wallet-core/src/operations/withdraw.ts   |  2 +-
 .../taler-wallet-core/src/util/promiseUtils.ts     | 17 ++++++++++-----
 packages/taler-wallet-core/src/util/query.ts       | 17 ++++++++++-----
 .../taler-wallet-webextension/src/wxBackend.ts     |  2 +-
 7 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/packages/taler-util/src/logging.ts 
b/packages/taler-util/src/logging.ts
index d17baba66..663bc59c8 100644
--- a/packages/taler-util/src/logging.ts
+++ b/packages/taler-util/src/logging.ts
@@ -37,6 +37,28 @@ const byTagLogLevel: Record<string, LogLevel> = {};
 
 let nativeLogging: boolean = false;
 
+
+// from 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString
+Error.prototype.toString = function () {
+  if (
+    this === null ||
+    (typeof this !== "object" && typeof this !== "function")
+  ) {
+    throw new TypeError();
+  }
+  let name = this.name;
+  name = name === undefined ? "Error" : `${name}`;
+  let msg = this.message;
+  msg = msg === undefined ? "" : `${msg}`;
+
+  let cause = ""
+  if ("cause" in this) {
+    cause = `\n Caused by: ${this.cause}`
+  }
+  return `${name}: ${msg}${cause}`;
+};
+
+
 export function getGlobalLogLevel(): string {
   return globalLogLevel;
 }
@@ -126,7 +148,7 @@ function writeNodeLog(
  * and uses the corresponding console.* method to log in the browser.
  */
 export class Logger {
-  constructor(private tag: string) {}
+  constructor(private tag: string) { }
 
   shouldLogTrace(): boolean {
     const level = byTagLogLevel[this.tag] ?? globalLogLevel;
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index b0605cb1d..705df48b1 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -3012,8 +3012,10 @@ function upgradeFromStoreMap(
           });
         } catch (e) {
           const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : "";
-          throw Error(
+          throw new Error(
             `Migration failed. Could not create store 
${swi.storeName}.${moreInfo}`,
+            // @ts-expect-error no support for options.cause yet
+            { cause: e },
           );
         }
       }
@@ -3040,6 +3042,8 @@ function upgradeFromStoreMap(
           const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : "";
           throw Error(
             `Migration failed. Could not create index 
${indexDesc.name}/${indexDesc.keyPath}. ${moreInfo}`,
+            // @ts-expect-error no support for options.cause yet
+            { cause: e },
           );
         }
       }
diff --git a/packages/taler-wallet-core/src/host-impl.node.ts 
b/packages/taler-wallet-core/src/host-impl.node.ts
index fefee1067..622ea742e 100644
--- a/packages/taler-wallet-core/src/host-impl.node.ts
+++ b/packages/taler-wallet-core/src/host-impl.node.ts
@@ -68,7 +68,11 @@ async function makeFileDb(
         logger.trace("wallet file doesn't exist yet");
       } else {
         logger.error("could not open wallet database file");
-        throw e;
+        throw Error(
+          "could not open wallet database file",
+          // @ts-expect-error no support for options.cause yet
+          { cause: e },
+        );
       }
     }
 
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts 
b/packages/taler-wallet-core/src/operations/withdraw.ts
index d664a6da6..86f05478a 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -2116,7 +2116,7 @@ async function registerReserveWithBank(
   if (
     withdrawalGroup.wgInfo.withdrawalType != 
WithdrawalRecordType.BankIntegrated
   ) {
-    throw Error();
+    throw Error("expecting withdrarwal type = bank integrated");
   }
   const bankInfo = withdrawalGroup.wgInfo.bankInfo;
   if (!bankInfo) {
diff --git a/packages/taler-wallet-core/src/util/promiseUtils.ts 
b/packages/taler-wallet-core/src/util/promiseUtils.ts
index df4cc343b..d152a12f4 100644
--- a/packages/taler-wallet-core/src/util/promiseUtils.ts
+++ b/packages/taler-wallet-core/src/util/promiseUtils.ts
@@ -23,6 +23,7 @@ export interface OpenedPromise<T> {
   promise: Promise<T>;
   resolve: (val: T) => void;
   reject: (err: any) => void;
+  lastError?: any;
 }
 
 /**
@@ -33,16 +34,22 @@ export interface OpenedPromise<T> {
  */
 export function openPromise<T>(): OpenedPromise<T> {
   let resolve: ((x?: any) => void) | null = null;
-  let reject: ((reason?: any) => void) | null = null;
+  let promiseReject: ((reason?: any) => void) | null = null;
   const promise = new Promise<T>((res, rej) => {
     resolve = res;
-    reject = rej;
+    promiseReject = rej;
   });
-  if (!(resolve && reject)) {
+  if (!(resolve && promiseReject)) {
     // Never happens, unless JS implementation is broken
-    throw Error();
+    throw Error("JS implementation is broken");
   }
-  return { resolve, reject, promise };
+  const result: OpenedPromise<T> = { resolve, reject: promiseReject, promise };
+  function saveLastError(reason?: any) {
+    result.lastError = reason;
+    promiseReject!(reason);
+  }
+  result.reject = saveLastError;
+  return result;
 }
 
 export class AsyncCondition {
diff --git a/packages/taler-wallet-core/src/util/query.ts 
b/packages/taler-wallet-core/src/util/query.ts
index efb1a3f42..8274e252b 100644
--- a/packages/taler-wallet-core/src/util/query.ts
+++ b/packages/taler-wallet-core/src/util/query.ts
@@ -34,6 +34,7 @@ import {
   IDBCursor,
   IDBKeyPath,
   IDBKeyRange,
+  IDBOpenDBRequest,
 } from "@gnu-taler/idb-bridge";
 import { Codec, Logger, j2s } from "@gnu-taler/taler-util";
 
@@ -250,9 +251,9 @@ export function openDatabase(
 ): Promise<IDBDatabase> {
   return new Promise<IDBDatabase>((resolve, reject) => {
     const req = idbFactory.open(databaseName, databaseVersion);
-    req.onerror = (e) => {
-      logger.error("database error", e);
-      reject(new Error("database error"));
+    req.onerror = (event) => {
+      // @ts-expect-error
+      reject(new Error(`database opening error`, { cause: req.error }));
     };
     req.onsuccess = (e) => {
       req.result.onversionchange = (evt: IDBVersionChangeEvent) => {
@@ -268,11 +269,17 @@ export function openDatabase(
       const db = req.result;
       const newVersion = e.newVersion;
       if (!newVersion) {
-        throw Error("upgrade needed, but new version unknown");
+        // @ts-expect-error
+        throw Error("upgrade needed, but new version unknown", {
+          cause: req.error,
+        });
       }
       const transaction = req.transaction;
       if (!transaction) {
-        throw Error("no transaction handle available in upgrade handler");
+        // @ts-expect-error
+        throw Error("no transaction handle available in upgrade handler", {
+          cause: req.error,
+        });
       }
       logger.info(
         `handling upgradeneeded event on ${databaseName} from ${e.oldVersion} 
to ${e.newVersion}`,
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts 
b/packages/taler-wallet-webextension/src/wxBackend.ts
index 95d31c519..c8df7d6ca 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -232,7 +232,7 @@ async function dispatch<
           error: makeErrorDetail(
             TalerErrorCode.WALLET_CORE_NOT_AVAILABLE,
             {},
-            "wallet core not available",
+            `wallet core not available, last error: ${walletInit.lastError}`,
           ),
         };
       }

-- 
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]