sentry-javascript
sentry-javascript copied to clipboard
Caught/Handled exceptions are always being logged as unhandled (@sentry/serverless)
Is there an existing issue for this?
- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [X] I have reviewed the documentation https://docs.sentry.io/
- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/serverless
SDK Version
7.6.0
Framework Version
7.6.0
Link to Sentry event
https://sentry.io/organizations/kitup-stage/issues/3418028253/events/3127d807ee0e4ba2bda444c287041aad/?project=6521764
Steps to Reproduce
- Create a Lambda function and wrap it with the
Sentry.AWSLambda.wrapHandler() - Create a try/catch block
- In the try block, throw an error
- In the catch block, call
Sentry.captureException(error)to catch and log the error - Expected behavior is that the
handledtag is set totruebecause the error or exception was caught within the tr/catch and not thewrapHandler. However, the caught error is always flagged as unhandledhandled:false
This might be the relevant code according to this Discord discussion in Sentry discord : https://github.com/getsentry/sentry-javascript/blob/ce67a38259a4fb9ac9753a7bf3991ada78cc6102/packages/serverless/src/utils.ts#L12-L18
Expected Result
Errors caught within a try/catch block and logged in the catch statement with Sentry.captureException(error) should be marked as handled:true
Actual Result
Errors caught within the try/catch block are always marked as handled:false.

related: https://github.com/getsentry/sentry-javascript/issues/5375, though that's the opposite problem.
I think we're going to take a look at handled in general - we should write up a new GH issue summarizing all the problems and gather feedback accordingly.
In the meantime, @whats-a-handle appreciate your patience while we engage in some due diligence to make sure we cover all the cases appropriately.
I know it's been over a year, but I wanted to follow up on this because I just ran into this at work (calling Sentry.captureException in a Node backend and having it arrive in Sentry as "unhandled"). I notice the issue is open but it's had the backlog label removed; is the plan to leave the current behavior as-is?
Opened https://github.com/getsentry/sentry-javascript/pull/9368 to fix this, thanks for the reminder @rtfeldman!
Awesome, thank you so much! 😃
Change was released with https://github.com/getsentry/sentry-javascript/releases/tag/7.76.0