From 88ae1d4442ff0c0f14a9d6b1583e48a942fac131 Mon Sep 17 00:00:00 2001 From: Tadej Golobic Date: Tue, 2 Apr 2024 15:01:27 +0200 Subject: [PATCH] fix(exceptions): add message to exceptions that are missing message (#2623) * fix(backend): error messages without any message * fix(masl): error messages without any message --------- Co-authored-by: tadejgolobic --- packages/backend/src/accounting/service.ts | 4 ++-- .../backend/src/accounting/tigerbeetle/utils.ts | 2 +- .../backend/src/graphql/resolvers/liquidity.ts | 4 ++-- .../open_payments/payment/incoming/service.ts | 2 +- .../backend/src/open_payments/quote/model.ts | 2 +- packages/backend/src/tests/outgoingPayment.ts | 2 +- packages/backend/src/tests/quote.ts | 16 ++++++++-------- .../src/account-provider.ts | 14 +++++++------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/backend/src/accounting/service.ts b/packages/backend/src/accounting/service.ts index a7c0e18400..2894023dfb 100644 --- a/packages/backend/src/accounting/service.ts +++ b/packages/backend/src/accounting/service.ts @@ -162,7 +162,7 @@ export async function createAccountToAccountTransfer( const balance = await getAccountBalance(account.id) if (balance === undefined) { - throw new Error() + throw new Error('undefined account balance') } await account.onDebit({ @@ -188,7 +188,7 @@ export async function createAccountToAccountTransfer( const totalReceived = await getAccountReceived(destinationAccount.id) if (totalReceived === undefined) { - throw new Error() + throw new Error('total received is undefined') } await destinationAccount.onCredit({ diff --git a/packages/backend/src/accounting/tigerbeetle/utils.ts b/packages/backend/src/accounting/tigerbeetle/utils.ts index b645cb6e9e..b9b1e32660 100644 --- a/packages/backend/src/accounting/tigerbeetle/utils.ts +++ b/packages/backend/src/accounting/tigerbeetle/utils.ts @@ -10,7 +10,7 @@ export function toTigerbeetleId(id: AccountId): bigint { return id } if (!validateId(id)) { - throw new Error() + throw new Error('wrong format of id') } return uuidToBigInt(id) diff --git a/packages/backend/src/graphql/resolvers/liquidity.ts b/packages/backend/src/graphql/resolvers/liquidity.ts index f8edac9773..0659ad78c1 100644 --- a/packages/backend/src/graphql/resolvers/liquidity.ts +++ b/packages/backend/src/graphql/resolvers/liquidity.ts @@ -385,7 +385,7 @@ export const depositEventLiquidity: MutationResolvers['depositEve return responses[LiquidityError.InvalidId] } if (!event.data.debitAmount) { - throw new Error() + throw new Error('missing debit amount') } const outgoingPaymentService = await ctx.container.use( 'outgoingPaymentService' @@ -434,7 +434,7 @@ export const withdrawEventLiquidity: MutationResolvers['withdrawE const assetService = await ctx.container.use('assetService') const asset = await assetService.get(event.withdrawal.assetId) if (!asset) { - throw new Error() + throw new Error('asset id does not map to asset') } const accountingService = await ctx.container.use('accountingService') const error = await accountingService.createWithdrawal({ diff --git a/packages/backend/src/open_payments/payment/incoming/service.ts b/packages/backend/src/open_payments/payment/incoming/service.ts index 533c687f04..9311d0874c 100644 --- a/packages/backend/src/open_payments/payment/incoming/service.ts +++ b/packages/backend/src/open_payments/payment/incoming/service.ts @@ -207,7 +207,7 @@ async function handleDeactivated( incomingPayment: IncomingPayment ): Promise { if (!incomingPayment.processAt) { - throw new Error() + throw new Error('processAt field is not defined') } try { const amountReceived = await deps.accountingService.getTotalReceived( diff --git a/packages/backend/src/open_payments/quote/model.ts b/packages/backend/src/open_payments/quote/model.ts index f636bb34e2..84add91113 100644 --- a/packages/backend/src/open_payments/quote/model.ts +++ b/packages/backend/src/open_payments/quote/model.ts @@ -144,7 +144,7 @@ export class Quote extends WalletAddressSubresource { Pay.Int.from(this.highEstimatedExchangeRateDenominator) as Pay.PositiveInt ) if (!highEstimatedExchangeRate.isPositive()) { - throw new Error() + throw new Error('high estimated exchange rate is not positive') } return highEstimatedExchangeRate } diff --git a/packages/backend/src/tests/outgoingPayment.ts b/packages/backend/src/tests/outgoingPayment.ts index ec2f604e27..13d756653d 100644 --- a/packages/backend/src/tests/outgoingPayment.ts +++ b/packages/backend/src/tests/outgoingPayment.ts @@ -65,7 +65,7 @@ export async function createOutgoingPayment( quoteId: quote.id }) if (isOutgoingPaymentError(outgoingPaymentOrError)) { - throw new Error() + throw new Error(outgoingPaymentOrError) } const accountingService = await deps.use('accountingService') diff --git a/packages/backend/src/tests/quote.ts b/packages/backend/src/tests/quote.ts index 0287538996..85072b9da1 100644 --- a/packages/backend/src/tests/quote.ts +++ b/packages/backend/src/tests/quote.ts @@ -76,14 +76,14 @@ export async function createQuote( const walletAddressService = await deps.use('walletAddressService') const walletAddress = await walletAddressService.get(walletAddressId) if (!walletAddress) { - throw new Error() + throw new Error('wallet not found') } if ( debitAmount && (walletAddress.asset.code !== debitAmount.assetCode || walletAddress.asset.scale !== debitAmount.assetScale) ) { - throw new Error() + throw new Error('asset code or scale do not match') } const config = await deps.use('config') @@ -92,23 +92,23 @@ export async function createQuote( const receiverService = await deps.use('receiverService') const receiver = await receiverService.get(receiverUrl) if (!receiver) { - throw new Error() + throw new Error('receiver not found') } if (!receiver.incomingAmount && !receiveAmount && !debitAmount) { - throw new Error() + throw new Error('missing amount') } if (receiveAmount) { if ( receiver.assetCode !== receiveAmount.assetCode || receiver.assetScale !== receiveAmount.assetScale ) { - throw new Error() + throw new Error('asset code or asset scale do not match') } if ( receiver.incomingAmount && receiveAmount.value > receiver.incomingAmount.value ) { - throw new Error() + throw new Error('receive amount is higher than the incoming amount') } } else { receiveAsset = receiver.asset @@ -129,7 +129,7 @@ export async function createQuote( if (debitAmount) { if (!receiveAsset) { - throw new Error() + throw new Error('receive asset is not defined') } receiveAmount = { value: BigInt( @@ -143,7 +143,7 @@ export async function createQuote( } } else { if (!receiveAmount) { - throw new Error() + throw new Error('receive amount is not defined') } debitAmount = { value: BigInt( diff --git a/packages/mock-account-service-lib/src/account-provider.ts b/packages/mock-account-service-lib/src/account-provider.ts index 5be375a920..37554fadec 100644 --- a/packages/mock-account-service-lib/src/account-provider.ts +++ b/packages/mock-account-service-lib/src/account-provider.ts @@ -60,7 +60,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } acc.walletAddress = walletAddress @@ -139,7 +139,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } if (clearPending && acc.creditsPending - amount < 0) { @@ -167,7 +167,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } if ( @@ -200,7 +200,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } acc.creditsPending += amount @@ -217,7 +217,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } if (acc.creditsPosted < acc.debitsPosted + acc.debitsPending + amount) { @@ -238,7 +238,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } if (acc.debitsPending - amount < 0) { @@ -259,7 +259,7 @@ export class AccountProvider implements AccountsServer { const acc = this.accounts.get(id) if (!acc) { - throw new Error() + throw new Error('account not found') } if (acc.debitsPending - amount < 0) {