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

fix(core): Use last error for ignoreErrors check #8089

Merged
merged 1 commit into from
May 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ function _getPossibleEventMessages(event: Event): string[] {
return [event.message];
}
if (event.exception) {
const { values } = event.exception;
try {
const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
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)}`);
Expand Down
29 changes: 29 additions & 0 deletions packages/core/test/lib/integrations/inboundfilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ const EXCEPTION_EVENT_WITH_FRAMES: Event = {
},
};

const EXCEPTION_EVENT_WITH_LINKED_ERRORS: Event = {
exception: {
values: [
{
type: 'ReferenceError',
value: '`tooManyTreats` is not defined',
},
{
type: 'TypeError',
value: 'incorrect type given for parameter `chewToy`: Shoe',
},
],
},
};

const SENTRY_EVENT: Event = {
exception: {
values: [
Expand Down Expand Up @@ -271,6 +286,20 @@ describe('InboundFilters', () => {
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null);
});

it('filters on last exception when multiple present', () => {
const eventProcessor = createInboundFiltersEventProcessor({
ignoreErrors: ['incorrect type given for parameter `chewToy`'],
});
expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(null);
});

it("doesn't filter on `cause` exception when multiple present", () => {
const eventProcessor = createInboundFiltersEventProcessor({
ignoreErrors: ['`tooManyTreats` is not defined'],
});
expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(EXCEPTION_EVENT_WITH_LINKED_ERRORS);
});

describe('on exception', () => {
it('uses exception data when message is unavailable', () => {
const eventProcessor = createInboundFiltersEventProcessor({
Expand Down