aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-cli
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-03-22 21:16:38 +0100
committerFlorian Dold <florian@dold.me>2022-03-22 21:16:38 +0100
commit5d23eb36354d07508a015531f298b3e261bbafce (patch)
treefae0d2599c94d88c9264bb63a301adb1706824c1 /packages/taler-wallet-cli
parentf8d12f7b0d4af1b1769b89e80c87f9c169678564 (diff)
downloadwallet-core-5d23eb36354d07508a015531f298b3e261bbafce.tar.xz
wallet: improve error handling and error codes
Diffstat (limited to 'packages/taler-wallet-cli')
-rw-r--r--packages/taler-wallet-cli/src/harness/harness.ts14
-rw-r--r--packages/taler-wallet-cli/src/index.ts21
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts5
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts32
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts18
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts2
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts30
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts8
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts6
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts4
10 files changed, 74 insertions, 66 deletions
diff --git a/packages/taler-wallet-cli/src/harness/harness.ts b/packages/taler-wallet-cli/src/harness/harness.ts
index 63bb17fcc..46ddd0ed2 100644
--- a/packages/taler-wallet-cli/src/harness/harness.ts
+++ b/packages/taler-wallet-cli/src/harness/harness.ts
@@ -49,7 +49,7 @@ import {
HarnessExchangeBankAccount,
NodeHttpLib,
openPromise,
- OperationFailedError,
+ TalerError,
WalletCoreApiClient,
} from "@gnu-taler/taler-wallet-core";
import {
@@ -227,19 +227,19 @@ export class GlobalTestState {
this.servers = [];
}
- async assertThrowsOperationErrorAsync(
+ async assertThrowsTalerErrorAsync(
block: () => Promise<void>,
- ): Promise<OperationFailedError> {
+ ): Promise<TalerError> {
try {
await block();
} catch (e) {
- if (e instanceof OperationFailedError) {
+ if (e instanceof TalerError) {
return e;
}
- throw Error(`expected OperationFailedError to be thrown, but got ${e}`);
+ throw Error(`expected TalerError to be thrown, but got ${e}`);
}
throw Error(
- `expected OperationFailedError to be thrown, but block finished without throwing`,
+ `expected TalerError to be thrown, but block finished without throwing`,
);
}
@@ -1904,7 +1904,7 @@ export class WalletCli {
throw new Error("wallet CLI did not return a proper JSON response");
}
if (ar.type === "error") {
- throw new OperationFailedError(ar.error);
+ throw TalerError.fromUncheckedDetail(ar.error);
}
return ar.result;
},
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index f754ca915..e7b76fa9e 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -49,14 +49,13 @@ import {
import {
NodeHttpLib,
getDefaultNodeWallet,
- OperationFailedAndReportedError,
- OperationFailedError,
NodeThreadCryptoWorkerFactory,
CryptoApi,
walletCoreDebugFlags,
WalletApiOperation,
WalletCoreApiClient,
Wallet,
+ getErrorDetailFromException,
} from "@gnu-taler/taler-wallet-core";
import { lintExchangeDeployment } from "./lint.js";
import { runBench1 } from "./bench1.js";
@@ -206,18 +205,12 @@ async function withWallet<T>(
const ret = await f(w);
return ret;
} catch (e) {
- if (
- e instanceof OperationFailedAndReportedError ||
- e instanceof OperationFailedError
- ) {
- console.error("Operation failed: " + e.message);
- console.error(
- "Error details:",
- JSON.stringify(e.operationError, undefined, 2),
- );
- } else {
- console.error("caught unhandled exception (bug?):", e);
- }
+ const ed = getErrorDetailFromException(e);
+ console.error("Operation failed: " + ed.message);
+ console.error(
+ "Error details:",
+ JSON.stringify(ed.operationError, undefined, 2),
+ );
process.exit(1);
} finally {
logger.info("operation with wallet finished, stopping");
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts b/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts
index 8a11b79c6..97dbf369c 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts
@@ -32,7 +32,6 @@ import {
BankApi,
BankAccessApi,
CreditDebitIndicator,
- OperationFailedError,
} from "@gnu-taler/taler-wallet-core";
/**
@@ -104,10 +103,10 @@ export async function runBankApiTest(t: GlobalTestState) {
// Make sure that registering twice results in a 409 Conflict
{
- const e = await t.assertThrowsAsync(async () => {
+ const e = await t.assertThrowsTalerErrorAsync(async () => {
await BankApi.registerAccount(bank, "user1", "pw1");
});
- t.assertTrue(e.details.httpStatusCode === 409);
+ t.assertTrue(e.errorDetail.httpStatusCode === 409);
}
let balResp = await BankAccessApi.getAccountBalance(bank, bankUser);
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts b/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts
index 28cca0758..ec1d9f64b 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts
@@ -20,25 +20,21 @@
import {
PreparePayResultType,
TalerErrorCode,
- TalerErrorDetails,
- TransactionType,
+ TalerErrorDetail,
} from "@gnu-taler/taler-util";
-import {
- WalletApiOperation,
-} from "@gnu-taler/taler-wallet-core";
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { makeEventId } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
-import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js";
+import {
+ createSimpleTestkudosEnvironment,
+ withdrawViaBank,
+} from "../harness/helpers.js";
export async function runDenomUnofferedTest(t: GlobalTestState) {
// Set up test environment
- const {
- wallet,
- bank,
- exchange,
- merchant,
- } = await createSimpleTestkudosEnvironment(t);
+ const { wallet, bank, exchange, merchant } =
+ await createSimpleTestkudosEnvironment(t);
// Withdraw digital cash into the wallet.
@@ -95,19 +91,23 @@ export async function runDenomUnofferedTest(t: GlobalTestState) {
preparePayResult.status === PreparePayResultType.PaymentPossible,
);
- const exc = await t.assertThrowsAsync(async () => {
+ const exc = await t.assertThrowsTalerErrorAsync(async () => {
await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId,
});
});
- const errorDetails: TalerErrorDetails = exc.operationError;
+ t.assertTrue(
+ exc.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED),
+ );
+
// FIXME: We might want a more specific error code here!
t.assertDeepEqual(
- errorDetails.code,
+ exc.errorDetail.innerError.code,
TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
);
- const merchantErrorCode = (errorDetails.details as any).errorResponse.code;
+ const merchantErrorCode = (exc.errorDetail.innerError.errorResponse as any)
+ .code;
t.assertDeepEqual(
merchantErrorCode,
TalerErrorCode.MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND,
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
index f9c7c4b99..dc650830d 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
@@ -181,16 +181,22 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
},
});
- const err1 = await t.assertThrowsOperationErrorAsync(async () => {
+ const err1 = await t.assertThrowsTalerErrorAsync(async () => {
await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: faultyExchange.baseUrl,
});
});
+ // Updating the exchange from the base URL is technically a pending operation
+ // and it will be retried later.
+ t.assertTrue(
+ err1.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED),
+ );
+
// Response is malformed, since it didn't even contain a version code
// in a format the wallet can understand.
t.assertTrue(
- err1.operationError.code ===
+ err1.errorDetail.innerError.code ===
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
);
@@ -223,14 +229,18 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
},
});
- const err2 = await t.assertThrowsOperationErrorAsync(async () => {
+ const err2 = await t.assertThrowsTalerErrorAsync(async () => {
await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: faultyExchange.baseUrl,
});
});
t.assertTrue(
- err2.operationError.code ===
+ err2.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED),
+ );
+
+ t.assertTrue(
+ err2.errorDetail.innerError.code ===
TalerErrorCode.WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE,
);
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
index 0fa9ec81d..09b546f46 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
@@ -123,7 +123,7 @@ export async function runPayAbortTest(t: GlobalTestState) {
},
});
- await t.assertThrowsOperationErrorAsync(async () => {
+ await t.assertThrowsTalerErrorAsync(async () => {
await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId,
});
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts
index ba3bd8e0a..e878854f8 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts
@@ -17,8 +17,15 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi, WalletCli } from "../harness/harness.js";
-import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js";
+import {
+ GlobalTestState,
+ MerchantPrivateApi,
+ WalletCli,
+} from "../harness/harness.js";
+import {
+ createSimpleTestkudosEnvironment,
+ withdrawViaBank,
+} from "../harness/helpers.js";
import { PreparePayResultType } from "@gnu-taler/taler-util";
import { TalerErrorCode } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
@@ -29,12 +36,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
export async function runPaymentClaimTest(t: GlobalTestState) {
// Set up test environment
- const {
- wallet,
- bank,
- exchange,
- merchant,
- } = await createSimpleTestkudosEnvironment(t);
+ const { wallet, bank, exchange, merchant } =
+ await createSimpleTestkudosEnvironment(t);
const walletTwo = new WalletCli(t, "two");
@@ -73,7 +76,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
preparePayResult.status === PreparePayResultType.PaymentPossible,
);
- t.assertThrowsOperationErrorAsync(async () => {
+ t.assertThrowsTalerErrorAsync(async () => {
await walletTwo.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri,
});
@@ -93,14 +96,19 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
walletTwo.deleteDatabase();
- const err = await t.assertThrowsOperationErrorAsync(async () => {
+ const err = await t.assertThrowsTalerErrorAsync(async () => {
await walletTwo.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri,
});
});
t.assertTrue(
- err.operationError.code === TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED,
+ err.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED),
+ );
+
+ t.assertTrue(
+ err.errorDetail.innerError.code ===
+ TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED,
);
await t.shutdown();
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
index 75d44d495..7e178077e 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
@@ -32,7 +32,7 @@ import {
ConfirmPayResultType,
PreparePayResultType,
TalerErrorCode,
- TalerErrorDetails,
+ TalerErrorDetail,
URL,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
@@ -135,11 +135,9 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
}
faultInjected = true;
console.log("injecting pay fault");
- const err: TalerErrorDetails = {
+ const err: TalerErrorDetail = {
code: TalerErrorCode.GENERIC_DB_COMMIT_FAILED,
- details: {},
- hint: "huh",
- message: "something went wrong",
+ hint: "something went wrong",
};
ctx.responseBody = Buffer.from(JSON.stringify(err));
ctx.statusCode = 500;
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts b/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts
index 93c22af70..146603f3a 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts
@@ -26,9 +26,9 @@ import {
findDenomOrThrow,
generateReserveKeypair,
NodeHttpLib,
- OperationFailedError,
refreshCoin,
SynchronousCryptoWorkerFactory,
+ TalerError,
topupReserveWithDemobank,
withdrawCoin,
} from "@gnu-taler/taler-wallet-core";
@@ -95,9 +95,9 @@ export async function runWalletDblessTest(t: GlobalTestState) {
newDenoms: refreshDenoms,
});
} catch (e) {
- if (e instanceof OperationFailedError) {
+ if (e instanceof TalerError) {
console.log(e);
- console.log(j2s(e.operationError));
+ console.log(j2s(e.errorDetail));
} else {
console.log(e);
}
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts b/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts
index 19668d760..0125b3b41 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts
@@ -63,7 +63,7 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
//
// WHY ?!
//
- const e = await t.assertThrowsOperationErrorAsync(async () => {
+ const e = await t.assertThrowsTalerErrorAsync(async () => {
await wallet.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal,
{
@@ -73,7 +73,7 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
);
});
t.assertDeepEqual(
- e.operationError.code,
+ e.errorDetail.code,
TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK,
);