sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Caught/Handled exceptions are always being logged as unhandled (@sentry/serverless)

Open whats-a-handle opened this issue 3 years ago • 2 comments

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

  1. Create a Lambda function and wrap it with the Sentry.AWSLambda.wrapHandler()
  2. Create a try/catch block
  3. In the try block, throw an error
  4. In the catch block, call Sentry.captureException(error) to catch and log the error
  5. Expected behavior is that the handled tag is set to true because the error or exception was caught within the tr/catch and not the wrapHandler. However, the caught error is always flagged as unhandled handled: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. Screen Shot 2022-07-11 at 2 26 27 PM

whats-a-handle avatar Jul 11 '22 21:07 whats-a-handle

related: https://github.com/getsentry/sentry-javascript/issues/5375, though that's the opposite problem.

lobsterkatie avatar Jul 12 '22 04:07 lobsterkatie

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.

AbhiPrasad avatar Jul 12 '22 13:07 AbhiPrasad

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?

rtfeldman avatar Oct 24 '23 23:10 rtfeldman

Opened https://github.com/getsentry/sentry-javascript/pull/9368 to fix this, thanks for the reminder @rtfeldman!

AbhiPrasad avatar Oct 25 '23 14:10 AbhiPrasad

Awesome, thank you so much! 😃

rtfeldman avatar Oct 25 '23 15:10 rtfeldman

Change was released with https://github.com/getsentry/sentry-javascript/releases/tag/7.76.0

AbhiPrasad avatar Oct 27 '23 16:10 AbhiPrasad