Skip to content

Commit

Permalink
refactor: Catch all user triggered errors (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethfuller authored Jul 5, 2023
1 parent 649784e commit 389149f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { VeBalLockInfo } from '@/services/balancer/contracts/contracts/veBAL';
import { ApprovalAction } from '@/composables/approvals/types';
import { captureException } from '@sentry/browser';
import useTokenApprovalActions from '@/composables/approvals/useTokenApprovalActions';
import { isUserRejected } from '@/composables/useTransactionErrors';
import { isUserError } from '@/composables/useTransactionErrors';
/**
* TYPES
Expand Down Expand Up @@ -188,7 +188,7 @@ async function submit(lockType: LockType, actionIndex: number) {
// An exception is already logged in balancerContractsService, but we should
// log another here in case any exceptions are thrown before it's sent
if (!isUserRejected(error)) {
if (!isUserError(error)) {
captureException(error, {
level: 'fatal',
extra: {
Expand Down
5 changes: 2 additions & 3 deletions src/composables/swap/useCowswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import useTransactions from '../useTransactions';
import { SwapQuote } from './types';
import { captureException } from '@sentry/browser';
import { Goals, trackGoal } from '../useFathom';
import useTransactionErrors from '../useTransactionErrors';
import { isUserError } from '../useTransactionErrors';
import { useI18n } from 'vue-i18n';
import { useApp } from '@/composables/useApp';

Expand Down Expand Up @@ -93,7 +93,6 @@ export default function useCowswap({
const { addTransaction } = useTransactions();
const { fNum } = useNumbers();
const { balanceFor } = useTokens();
const { isUserRejected } = useTransactionErrors();
const { t } = useI18n();

// DATA
Expand Down Expand Up @@ -238,7 +237,7 @@ export default function useCowswap({
confirming.value = false;
trackGoal(Goals.CowswapSwap);
} catch (error) {
if (!isUserRejected(error)) {
if (!isUserError(error)) {
console.trace(error);
state.submissionError = t('swapException', ['Cowswap']);
captureException(new Error(state.submissionError, { cause: error }), {
Expand Down
5 changes: 2 additions & 3 deletions src/composables/swap/useJoinExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import useEthers from '../useEthers';
import useRelayerApprovalQuery from '@/composables/queries/useRelayerApprovalQuery';
import { TransactionBuilder } from '@/services/web3/transactions/transaction.builder';
import BatchRelayerAbi from '@/lib/abi/BatchRelayer.json';
import useTransactionErrors from '../useTransactionErrors';
import { isUserError } from '../useTransactionErrors';
import { useI18n } from 'vue-i18n';

type JoinExitState = {
Expand Down Expand Up @@ -91,7 +91,6 @@ export default function useJoinExit({
const { addTransaction } = useTransactions();
const { txListener } = useEthers();
const { fNum } = useNumbers();
const { isUserRejected } = useTransactionErrors();
const { t } = useI18n();

const hasValidationError = computed(
Expand Down Expand Up @@ -237,7 +236,7 @@ export default function useJoinExit({
},
});
} catch (error) {
if (!isUserRejected(error)) {
if (!isUserError(error)) {
console.trace(error);
state.submissionError = t('swapException', ['Relayer']);
captureException(new Error(state.submissionError, { cause: error }), {
Expand Down
5 changes: 2 additions & 3 deletions src/composables/swap/useSor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import useTransactions, { TransactionAction } from '../useTransactions';
import { SwapQuote } from './types';
import { captureException } from '@sentry/browser';
import { overflowProtected } from '@/components/_global/BalTextInput/helpers';
import useTransactionErrors from '../useTransactionErrors';
import { isUserError } from '../useTransactionErrors';

type SorState = {
validationErrors: {
Expand Down Expand Up @@ -204,7 +204,6 @@ export default function useSor({
const { fNum, toFiat } = useNumbers();
const { t } = useI18n();
const { injectTokens, priceFor, getToken } = useTokens();
const { isUserRejected } = useTransactionErrors();
const { swapIn, swapOut } = useSwapper();

onMounted(async () => {
Expand Down Expand Up @@ -799,7 +798,7 @@ export default function useSor({
}

function handleSwapException(error: Error) {
if (!isUserRejected(error)) {
if (!isUserError(error)) {
console.trace(error);
state.submissionError = t('swapException', ['Balancer']);
captureException(new Error(state.submissionError, { cause: error }));
Expand Down
8 changes: 6 additions & 2 deletions src/composables/useTransactionErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function isErrorType(error, messages: RegExp[]): boolean {
return false;
}

// Errors that are caused by the user or the state of their wallet.
export function isUserError(error): boolean {
return isUserRejected(error) || isUserNotEnoughGas(error);
}

export default function useTransactionErrors() {
/**
* COMPOSABLES
Expand Down Expand Up @@ -106,8 +111,7 @@ export default function useTransactionErrors() {
* METHODS
*/
function parseError(error): TransactionError | null {
if (isUserRejected(error)) return null; // User rejected transaction
if (isUserNotEnoughGas(error)) return null; // User does not have enough gas
if (isUserError(error)) return null;
if (error?.code && error.code === 'UNPREDICTABLE_GAS_LIMIT')
return cannotEstimateGasError;

Expand Down
4 changes: 2 additions & 2 deletions src/providers/local/join-pool.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import useTokenApprovalActions from '@/composables/approvals/useTokenApprovalAct
import { useApp } from '@/composables/useApp';
import { throwQueryError } from '@/lib/utils/queries';
import { ApprovalAction } from '@/composables/approvals/types';
import { isUserRejected } from '@/composables/useTransactionErrors';
import { isUserError } from '@/composables/useTransactionErrors';

/**
* TYPES
Expand Down Expand Up @@ -376,7 +376,7 @@ export const joinPoolProvider = (
}

async function logJoinException(error: Error) {
if (isUserRejected(error)) return;
if (isUserError(error)) return;

const sender = await getSigner().getAddress();
captureException(error, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUserRejected } from '@/composables/useTransactionErrors';
import { isUserError } from '@/composables/useTransactionErrors';
import { configService } from '@/services/config/config.service';
import { gasService } from '@/services/gas/gas.service';
import { rpcProviderService } from '@/services/rpc-provider/rpc-provider.service';
Expand All @@ -11,6 +11,6 @@ export class TransactionConcern {
) {}

public shouldLogFailure(error): boolean {
return this.config.env.APP_ENV !== 'development' && !isUserRejected(error);
return this.config.env.APP_ENV !== 'development' && !isUserError(error);
}
}

1 comment on commit 389149f

@vercel
Copy link

@vercel vercel bot commented on 389149f Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.