Skip to content

Commit

Permalink
fix(core): Always use event message and exception values for `ignoreE…
Browse files Browse the repository at this point in the history
…rrors` (#8986)
  • Loading branch information
lforst committed Sep 8, 2023
1 parent f63b33b commit b190015
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
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

0 comments on commit b190015

Please sign in to comment.