Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prevent sending errors from old releases to Sentry #3605

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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