Skip to content

Commit

Permalink
feat: ignore or directly send errors to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron committed Jan 27, 2025
1 parent 9134c03 commit 2d7cd83
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 15 deletions.
36 changes: 21 additions & 15 deletions packages/app/src/systems/Error/services/ReportErrorService.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StoredFuelWalletError } from '@fuel-wallet/types';
import * as Sentry from '@sentry/react';
import { db } from '~/systems/Core/utils/database';
import { captureException } from '~/systems/Error/utils/captureException';
import { getErrorIgnoreData } from '~/systems/Error/utils/getErrorIgnoreData';
import { parseFuelError } from '../utils';

export class ReportErrorService {
Expand All @@ -18,21 +18,27 @@ export class ReportErrorService {
}

static async saveError(error: Error) {
const parsedError = parseFuelError(error);
if (!parsedError) {
console.warn(`Can't save error without a message`);
return;
}
if (!('id' in parsedError)) {
console.warn(`Can't save error without an id`);
return;
}
if (!db.isOpen() || db.hasBeenClosed()) {
console.warn('Error saving error: db is closed');
return;
}

try {
const parsedError = parseFuelError(error);
const ignoreData = getErrorIgnoreData(parsedError?.error);
if (!parsedError) {
console.warn(`Can't save error without a message`);
return;
}
if (!('id' in parsedError)) {
console.warn(`Can't save error without an id`);
return;
}
if (ignoreData?.action === 'ignore') return;
if (ignoreData?.action === 'hide') {
// Directly report to Sentry and exit
captureException(parsedError.error, parsedError.extra);
return;
}
if (!db.isOpen() || db.hasBeenClosed()) {
console.warn('Error saving error: db is closed');
return;
}
return await db.errors.add(parsedError);
} catch (e) {
console.warn('Failed to save error', e);
Expand Down
77 changes: 77 additions & 0 deletions packages/app/src/systems/Error/utils/getErrorIgnoreData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
type IgnoredError = {
value: string;
field: 'message' | 'stack' | 'name';
comparison: 'exact' | 'partial' | 'startsWith';
/**
* @description Whether to ignore the error or hide it from Report Error screen. Avoid ignoring errors that might contain sensitive information.
*/
action: 'ignore' | 'hide';
};

export function getErrorIgnoreData(
error: Error | undefined
): IgnoredError | undefined {
return IGNORED_ERRORS.find((filter) => {
const errorValue = error?.[filter.field] as string | undefined;

switch (filter.comparison) {
case 'exact':
return filter.value === errorValue;
case 'startsWith':
return errorValue?.startsWith(filter.value);
case 'partial':
return errorValue?.includes(filter.value);
}
});
}

const IGNORED_ERRORS: IgnoredError[] = [
{
value: 'Out of sync',
field: 'message',
comparison: 'exact',
action: 'hide',
},
{
value: 'Failed to fetch',
field: 'message',
comparison: 'exact',
action: 'hide',
},
{
value: 'TypeError:',
field: 'stack',
comparison: 'startsWith',
action: 'ignore',
},
{
value: 'NotFoundError',
field: 'name',
comparison: 'exact',
action: 'hide',
},
{
value: 'The browser is shutting down.',
field: 'message',
comparison: 'partial',
action: 'hide',
},
{
value: 'Error fetching asset from db',
field: 'message',
comparison: 'partial',
action: 'hide',
},
{
value: 'Cannot read properties of undefined',
field: 'message',
comparison: 'partial',
action: 'hide',
},
{
value: 'Params are required',
field: 'message',
comparison: 'partial',
action: 'hide',
},
];

0 comments on commit 2d7cd83

Please sign in to comment.