Skip to content

Commit

Permalink
fix(core): Use last error for ignoreErrors check (#8089)
Browse files Browse the repository at this point in the history
This fixes a helper function used in our implementation of `ignoreErrors` so that in the case of linked errors, it filters on the primary error (the one directly caught by `captureException`) rather than the error in the primary error's `cause` property[1]. See #8079 for screenshots and a more detailed explanation.

Fixes #8079.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
  • Loading branch information
lobsterkatie committed May 10, 2023
1 parent cbe8a57 commit a70a91a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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

0 comments on commit a70a91a

Please sign in to comment.