Skip to content

Commit

Permalink
fix(exceptions): add message to exceptions that are missing message (#…
Browse files Browse the repository at this point in the history
…2623)

* fix(backend): error messages without any message

* fix(masl): error messages without any message

---------

Co-authored-by: tadejgolobic <tadej.golobic@gatehub.net>
  • Loading branch information
golobitch and tadejgolobic authored Apr 2, 2024
1 parent ae859a9 commit 88ae1d4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/accounting/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/accounting/tigerbeetle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/graphql/resolvers/liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export const depositEventLiquidity: MutationResolvers<ApolloContext>['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'
Expand Down Expand Up @@ -434,7 +434,7 @@ export const withdrawEventLiquidity: MutationResolvers<ApolloContext>['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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function handleDeactivated(
incomingPayment: IncomingPayment
): Promise<void> {
if (!incomingPayment.processAt) {
throw new Error()
throw new Error('processAt field is not defined')
}
try {
const amountReceived = await deps.accountingService.getTotalReceived(
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/open_payments/quote/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/tests/outgoingPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 8 additions & 8 deletions packages/backend/src/tests/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions packages/mock-account-service-lib/src/account-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 88ae1d4

Please sign in to comment.