gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 01/02: -error reporting, code formatting


From: gnunet
Subject: [taler-wallet-core] 01/02: -error reporting, code formatting
Date: Tue, 31 May 2022 15:44:26 +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 2e6f3b356971f3a56ff78db0ea6fa75ce0ab85b2
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue May 31 15:08:31 2022 +0200

    -error reporting, code formatting
---
 packages/taler-wallet-cli/src/index.ts   | 44 ++++++++++++++++++++++----------
 packages/taler-wallet-core/src/errors.ts | 14 +++++++++-
 packages/taler-wallet-core/src/wallet.ts |  2 +-
 3 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/packages/taler-wallet-cli/src/index.ts 
b/packages/taler-wallet-cli/src/index.ts
index cec682b0..ebcee205 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -63,6 +63,7 @@ import {
   SynchronousCryptoWorkerFactory,
   nativeCrypto,
   performanceNow,
+  summarizeTalerErrorDetail,
 } from "@gnu-taler/taler-wallet-core";
 import { lintExchangeDeployment } from "./lint.js";
 import { runBench1 } from "./bench1.js";
@@ -237,11 +238,8 @@ async function withWallet<T>(
     return ret;
   } catch (e) {
     const ed = getErrorDetailFromException(e);
-    console.error("Operation failed: " + ed.message);
-    console.error(
-      "Error details:",
-      JSON.stringify(ed.operationError, undefined, 2),
-    );
+    console.error("Operation failed: " + summarizeTalerErrorDetail(ed));
+    console.error("Error details:", JSON.stringify(ed, undefined, 2));
     process.exit(1);
   } finally {
     logger.info("operation with wallet finished, stopping");
@@ -1085,7 +1083,7 @@ testCli
   .subcommand("withdrawTestkudos", "withdraw-testkudos")
   .action(async (args) => {
     await withWallet(args, async (wallet) => {
-      wallet.client.call(WalletApiOperation.WithdrawTestkudos, {});
+      await wallet.client.call(WalletApiOperation.WithdrawTestkudos, {});
     });
   });
 
@@ -1114,7 +1112,7 @@ class PerfTimer {
 
   stdev(nRuns: number) {
     const m = this.tSum / BigInt(nRuns);
-    const x = (this.tSumSq / BigInt(nRuns)) - m * m;
+    const x = this.tSumSq / BigInt(nRuns) - m * m;
     return Math.floor(Math.sqrt(Number(x)));
   }
 }
@@ -1123,7 +1121,7 @@ testCli
   .subcommand("benchmarkAgeRestrictions", "benchmark-age-restrictions")
   .requiredOption("reps", ["--reps"], clk.INT, {
     default: 100,
-    help: "repetitions (default: 100)"
+    help: "repetitions (default: 100)",
   })
   .action(async (args) => {
     const numReps = args.benchmarkAgeRestrictions.reps ?? 100;
@@ -1176,11 +1174,31 @@ testCli
       }
     }
 
-    console.log(`edx25519-commit (ns): ${tCommit.mean(numReps)} (stdev 
${tCommit.stdev(numReps)})`);
-    console.log(`edx25519-attest (ns): ${tAttest.mean(numReps)} (stdev 
${tAttest.stdev(numReps)})`);
-    console.log(`edx25519-verify (ns): ${tVerify.mean(numReps)} (stdev 
${tVerify.stdev(numReps)})`);
-    console.log(`edx25519-derive (ns): ${tDerive.mean(numReps)} (stdev 
${tDerive.stdev(numReps)})`);
-    console.log(`edx25519-compare (ns): ${tCompare.mean(numReps)} (stdev 
${tCompare.stdev(numReps)})`);
+    console.log(
+      `edx25519-commit (ns): ${tCommit.mean(numReps)} (stdev ${tCommit.stdev(
+        numReps,
+      )})`,
+    );
+    console.log(
+      `edx25519-attest (ns): ${tAttest.mean(numReps)} (stdev ${tAttest.stdev(
+        numReps,
+      )})`,
+    );
+    console.log(
+      `edx25519-verify (ns): ${tVerify.mean(numReps)} (stdev ${tVerify.stdev(
+        numReps,
+      )})`,
+    );
+    console.log(
+      `edx25519-derive (ns): ${tDerive.mean(numReps)} (stdev ${tDerive.stdev(
+        numReps,
+      )})`,
+    );
+    console.log(
+      `edx25519-compare (ns): ${tCompare.mean(numReps)} (stdev 
${tCompare.stdev(
+        numReps,
+      )})`,
+    );
   });
 
 testCli.subcommand("logtest", "logtest").action(async (args) => {
diff --git a/packages/taler-wallet-core/src/errors.ts 
b/packages/taler-wallet-core/src/errors.ts
index eda5444b..56017cc0 100644
--- a/packages/taler-wallet-core/src/errors.ts
+++ b/packages/taler-wallet-core/src/errors.ts
@@ -94,6 +94,11 @@ export function makePendingOperationFailedError(
   });
 }
 
+export function summarizeTalerErrorDetail(ed: TalerErrorDetail): string {
+  const errName = TalerErrorCode[ed.code] ?? "<unknown>";
+  return `Error (${ed.code}/${errName})`;
+}
+
 export class TalerError<T = any> extends Error {
   errorDetail: TalerErrorDetail & T;
   private constructor(d: TalerErrorDetail & T) {
@@ -107,7 +112,14 @@ export class TalerError<T = any> extends Error {
     detail: ErrBody<C>,
     hint?: string,
   ): TalerError {
-    // FIXME: include default hint?
+    if (!hint) {
+      const errName = TalerErrorCode[code];
+      if (errName) {
+        hint = `Error (${errName})`;
+      } else {
+        hint = `Error (<unknown>)`;
+      }
+    }
     return new TalerError<unknown>({ code, hint, ...detail });
   }
 
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 689e45f3..a0eaca2e 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -296,7 +296,7 @@ export async function runPending(
     } catch (e) {
       if (e instanceof TalerError) {
         console.error(
-          "Operation failed:",
+          "Pending operation failed:",
           JSON.stringify(e.errorDetail, undefined, 2),
         );
       } else {

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