Skip to content

Commit a70a91a

Browse files
authored
fix(core): Use last error for ignoreErrors check (#8089)
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
1 parent cbe8a57 commit a70a91a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ function _getPossibleEventMessages(event: Event): string[] {
152152
return [event.message];
153153
}
154154
if (event.exception) {
155+
const { values } = event.exception;
155156
try {
156-
const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
157+
const { type = '', value = '' } = (values && values[values.length - 1]) || {};
157158
return [`${value}`, `${type}: ${value}`];
158159
} catch (oO) {
159160
__DEBUG_BUILD__ && logger.error(`Cannot extract message for event ${getEventDescription(event)}`);

packages/core/test/lib/integrations/inboundfilters.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ const EXCEPTION_EVENT_WITH_FRAMES: Event = {
143143
},
144144
};
145145

146+
const EXCEPTION_EVENT_WITH_LINKED_ERRORS: Event = {
147+
exception: {
148+
values: [
149+
{
150+
type: 'ReferenceError',
151+
value: '`tooManyTreats` is not defined',
152+
},
153+
{
154+
type: 'TypeError',
155+
value: 'incorrect type given for parameter `chewToy`: Shoe',
156+
},
157+
],
158+
},
159+
};
160+
146161
const SENTRY_EVENT: Event = {
147162
exception: {
148163
values: [
@@ -271,6 +286,20 @@ describe('InboundFilters', () => {
271286
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null);
272287
});
273288

289+
it('filters on last exception when multiple present', () => {
290+
const eventProcessor = createInboundFiltersEventProcessor({
291+
ignoreErrors: ['incorrect type given for parameter `chewToy`'],
292+
});
293+
expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(null);
294+
});
295+
296+
it("doesn't filter on `cause` exception when multiple present", () => {
297+
const eventProcessor = createInboundFiltersEventProcessor({
298+
ignoreErrors: ['`tooManyTreats` is not defined'],
299+
});
300+
expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(EXCEPTION_EVENT_WITH_LINKED_ERRORS);
301+
});
302+
274303
describe('on exception', () => {
275304
it('uses exception data when message is unavailable', () => {
276305
const eventProcessor = createInboundFiltersEventProcessor({

0 commit comments

Comments
 (0)