Skip to content

fix(core): Always use event message and exception values for ignoreErrors #8986

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

Merged
merged 4 commits into from
Sep 8, 2023
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
35 changes: 25 additions & 10 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,35 @@ function _isAllowedUrl(event: Event, allowUrls?: Array<string | RegExp>): boolea
}

function _getPossibleEventMessages(event: Event): string[] {
const possibleMessages: string[] = [];

if (event.message) {
return [event.message];
possibleMessages.push(event.message);
}
if (event.exception) {
const { values } = event.exception;
try {
const { type = '', value = '' } = (values && values[values.length - 1]) || {};
return [`${value}`, `${type}: ${value}`];
} catch (oO) {
__DEBUG_BUILD__ && logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
return [];

let lastException;
try {
// @ts-ignore Try catching to save bundle size
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
lastException = event.exception.values[event.exception.values.length - 1];
} catch (e) {
// try catching to save bundle size checking existence of variables
}

if (lastException) {
if (lastException.value) {
possibleMessages.push(lastException.value);
if (lastException.type) {
possibleMessages.push(`${lastException.type}: ${lastException.value}`);
}
}
}
return [];

if (__DEBUG_BUILD__ && possibleMessages.length === 0) {
logger.error(`Could not extract message for event ${getEventDescription(event)}`);
}

return possibleMessages;
}

function _isSentryError(event: Event): boolean {
Expand Down
23 changes: 23 additions & 0 deletions packages/core/test/lib/integrations/inboundfilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ const EXCEPTION_EVENT: Event = {
},
};

const EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE: Event = {
message: 'ChunkError',
exception: {
values: [
{
type: 'SyntaxError',
value: 'unidentified ? at line 1337',
},
],
},
};

const EXCEPTION_EVENT_WITH_FRAMES: Event = {
exception: {
values: [
Expand Down Expand Up @@ -336,6 +348,17 @@ describe('InboundFilters', () => {
});
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
});

it('should consider both `event.message` and the last exceptions `type` and `value`', () => {
const messageEventProcessor = createInboundFiltersEventProcessor({
ignoreErrors: [/^ChunkError/],
});
const valueEventProcessor = createInboundFiltersEventProcessor({
ignoreErrors: [/^SyntaxError/],
});
expect(messageEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null);
expect(valueEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null);
});
});
});

Expand Down