Skip to content

Commit

Permalink
refactor: prevent sending errors from old releases
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Dec 5, 2024
1 parent 2df4fce commit 3a02e38
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-poems-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": patch
---

Prevent sending errors from old releases
14 changes: 3 additions & 11 deletions apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "vite",
"build": "NODE_OPTIONS=\"--max-old-space-size=16384\" && vite build",
"serve": "vite preview",
"test": "TZ=UTC VITE_NETWORK=testnet vitest run",
"test": "TZ=UTC VITE_NETWORK=testnet VITE_ENV=ci vitest run",
"test:regression": "reg-suit run",
"clean": "rm -rf .turbo && rm -rf node_modules",
"lint": "yarn lint:styles && biome check . --diagnostic-level=error",
Expand Down Expand Up @@ -157,15 +157,7 @@
"whatwg-fetch": "^3.6.18"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"production": [">0.2%", "not dead", "not op_mini all"],
"development": ["last 1 chrome version", "last 1 firefox version", "last 1 safari version"]
}
}
16 changes: 8 additions & 8 deletions apps/evm/src/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const App = () => (
)
}

<ErrorBoundary>
<HashRouter>
<MuiThemeProvider>
<QueryClientProvider client={queryClient}>
<HashRouter>
<MuiThemeProvider>
<QueryClientProvider client={queryClient}>
<ErrorBoundary>
<Web3Wrapper>
<AnalyticProvider>
<Routes />
Expand All @@ -60,10 +60,10 @@ const App = () => (
<SentryErrorInfo />
</AnalyticProvider>
</Web3Wrapper>
</QueryClientProvider>
</MuiThemeProvider>
</HashRouter>
</ErrorBoundary>
</ErrorBoundary>
</QueryClientProvider>
</MuiThemeProvider>
</HashRouter>
</>
);

Expand Down
24 changes: 21 additions & 3 deletions apps/evm/src/libs/errors/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as Sentry from '@sentry/react';
import useGetLatestAppVersion from 'clients/api/queries/getLatestAppVersion/useGetLatestAppVersion';
import { compareVersions } from 'compare-versions';

import config from 'config';
import { version as APP_VERSION } from 'constants/version';
Expand All @@ -21,6 +23,22 @@ Sentry.init({
],
});

export const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children }) => (
<Sentry.ErrorBoundary>{children}</Sentry.ErrorBoundary>
);
export const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children }) => {
const { data } = useGetLatestAppVersion();
const latestAppVersion = data?.version;

return (
<Sentry.ErrorBoundary
onError={e => {
// Prevent sending errors from old releases
if (latestAppVersion && compareVersions(latestAppVersion, APP_VERSION)) {
return undefined;
}

return e;
}}
>
{children}
</Sentry.ErrorBoundary>
);
};
4 changes: 2 additions & 2 deletions apps/evm/src/libs/errors/logError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as Sentry from '@sentry/react';
import config from 'config';

export const logError = (error: string | unknown) => {
// Only send errors to Sentry in hosted environments
if (config.environment !== 'preview' && config.environment !== 'production') {
// Only send errors to Sentry in production
if (config.environment !== 'production') {
console.error(`[Logger]: ${error}`);
return;
}
Expand Down

0 comments on commit 3a02e38

Please sign in to comment.