Skip to content

Commit b190015

Browse files
author
Luca Forstner
authored
fix(core): Always use event message and exception values for ignoreErrors (#8986)
1 parent f63b33b commit b190015

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,35 @@ function _isAllowedUrl(event: Event, allowUrls?: Array<string | RegExp>): boolea
169169
}
170170

171171
function _getPossibleEventMessages(event: Event): string[] {
172+
const possibleMessages: string[] = [];
173+
172174
if (event.message) {
173-
return [event.message];
175+
possibleMessages.push(event.message);
174176
}
175-
if (event.exception) {
176-
const { values } = event.exception;
177-
try {
178-
const { type = '', value = '' } = (values && values[values.length - 1]) || {};
179-
return [`${value}`, `${type}: ${value}`];
180-
} catch (oO) {
181-
__DEBUG_BUILD__ && logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
182-
return [];
177+
178+
let lastException;
179+
try {
180+
// @ts-ignore Try catching to save bundle size
181+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
182+
lastException = event.exception.values[event.exception.values.length - 1];
183+
} catch (e) {
184+
// try catching to save bundle size checking existence of variables
185+
}
186+
187+
if (lastException) {
188+
if (lastException.value) {
189+
possibleMessages.push(lastException.value);
190+
if (lastException.type) {
191+
possibleMessages.push(`${lastException.type}: ${lastException.value}`);
192+
}
183193
}
184194
}
185-
return [];
195+
196+
if (__DEBUG_BUILD__ && possibleMessages.length === 0) {
197+
logger.error(`Could not extract message for event ${getEventDescription(event)}`);
198+
}
199+
200+
return possibleMessages;
186201
}
187202

188203
function _isSentryError(event: Event): boolean {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ const EXCEPTION_EVENT: Event = {
125125
},
126126
};
127127

128+
const EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE: Event = {
129+
message: 'ChunkError',
130+
exception: {
131+
values: [
132+
{
133+
type: 'SyntaxError',
134+
value: 'unidentified ? at line 1337',
135+
},
136+
],
137+
},
138+
};
139+
128140
const EXCEPTION_EVENT_WITH_FRAMES: Event = {
129141
exception: {
130142
values: [
@@ -336,6 +348,17 @@ describe('InboundFilters', () => {
336348
});
337349
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
338350
});
351+
352+
it('should consider both `event.message` and the last exceptions `type` and `value`', () => {
353+
const messageEventProcessor = createInboundFiltersEventProcessor({
354+
ignoreErrors: [/^ChunkError/],
355+
});
356+
const valueEventProcessor = createInboundFiltersEventProcessor({
357+
ignoreErrors: [/^SyntaxError/],
358+
});
359+
expect(messageEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null);
360+
expect(valueEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null);
361+
});
339362
});
340363
});
341364

0 commit comments

Comments
 (0)