Skip to content

Sentry browser helper swallowing exception and not sending event #5887

@lpaulger

Description

@lpaulger

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

SDK Version

7.13.0

Framework Version

react 17.0.2

Link to Sentry event

No response

Steps to Reproduce

I have a react component where I observe a valid error because we access a prop of an undefined object. My concern is I am not seeing the error appear in Sentry, and while investigating, it seems that https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/helpers.ts#L117 exception is thrown and never sent to sentry and I can't understand why.

example react code where the error happens

state of my component which causes the error:

Categories = {};

myObject = {rule: {Category: 'MyCategory'}};
<strong 
  {Categories[myObject.rule.Category].title}
</strong>

When the error is thrown, it is being caught from within browser/src/helpers

TypeError: Cannot read properties of undefined (reading 'title')

Screen Shot 2022-10-05 at 17 15 29

Expected Result

line 117 of the helper throws the exception, I expect that it would be sent to sentry but it never appears.

I have set up a beforeSend within Sentry.init to verify all sent requests, and this case it is never called.

Sentry.init({
  dsn: "...",
  environment: "...",
  release: "...",
  beforeSend: (event, hint) => {
    console.log({ event, hint });

    // for debugging I want to see what goes to sentry
    return null;
  },
 
});

### Actual Result

thrown exception from react is never sent to Sentry. 

I'm not sure how to create a reproduction without a public sentry instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: reactIssues related to the Sentry React SDK

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions