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

SentryEvent does not return original exception

Open barisyild opened this issue 1 year ago • 13 comments

Platform

iOS

Environment

Production, Develop

Installed

Manually

Version

8.24.0

Xcode Version

15.4

Did it work on previous versions?

idk

Steps to Reproduce

  1. throw exception
  2. See error variable is empty.

Expected Result

Exception should appear in the Error variable.

Actual Result

image

Are you willing to submit a PR?

No response

### 🛑 Blocked by
- [ ] https://github.com/getsentry/sentry-cocoa/issues/2325

barisyild avatar Jul 17 '24 23:07 barisyild

Hello @barisyild, thanks for reaching out. You will find your exception in the exceptions property. The error property is meant for errors that happen while processing the event.

If I misunderstood your issue, please reach out and we will reopen it.

brustolin avatar Jul 18 '24 07:07 brustolin

Unfortunately this doesn't work for me because I need to read the original exception object.

barisyild avatar Jul 18 '24 07:07 barisyild

Sentry JavaScript SDK has originalException for this.

https://docs.sentry.io/platforms/javascript/configuration/filtering/#event-hints

barisyild avatar Jul 18 '24 09:07 barisyild

This is not related to crashes, but to handled exceptions then? Is this correct?

To understand this better:

How are you triggering the exception and how are you using Sentry to handle the event? Can you provide a snippet of your implementation?

brustolin avatar Jul 18 '24 09:07 brustolin

This is not related to crashes, but to handled exceptions then? Is this correct?

To understand this better:

How are you triggering the exception and how are you using Sentry to handle the event? Can you provide a snippet of your implementation?

I can summarize it like this; I throw special exceptions, and i want to send extra and context for these exceptions.

You can think of it like this; Some exception types are special and I need to take data from the variables in them and add them to the sentry data.

Example scenario; InterpreterException contains error details and lines related to the executed language.

I look at the Exception type and if it is InterpreterException I set extra and context.

barisyild avatar Jul 18 '24 10:07 barisyild

Right now, the Sentry Apple SDK doesn't keep the original exception in the event. This is something that we need to discuss.

brustolin avatar Jul 18 '24 12:07 brustolin

Right now, the Sentry Apple SDK doesn't keep the original exception in the event. This is something that we need to discuss.

I think all sentry targets should have ExceptionProcessor.

So can both override/replace/reject the exception and send extra data to the exception for its scope.

Like This; https://docs.sentry.io/platforms/javascript/enriching-events/event-processors/

Sentry.addExceptionProcessor

barisyild avatar Jul 18 '24 12:07 barisyild

Right now, the Sentry Apple SDK doesn't keep the original exception in the event. This is something that we need to discuss.

I think all sentry targets should have ExceptionProcessor.

So can both override/replace/reject the exception and send extra data to the exception for its scope.

Like This; https://docs.sentry.io/platforms/javascript/enriching-events/event-processors/

Sentry.addExceptionProcessor

Sometimes I need to catch exceptions inside some exceptions, I think processor is a must.

I wrote a custom captureException for this but it doesn't work for unhandled.

image

barisyild avatar Jul 18 '24 12:07 barisyild

I think all sentry targets should have ExceptionProcessor.

So can both override/replace/reject the exception and send extra data to the exception for its scope.

You can use beforeSend callback for this.

        SentrySDK.start { options in
            options.dsn = dsn
            options.beforeSend = { event in
                return event
            }
        }

brustolin avatar Jul 18 '24 13:07 brustolin

I think all sentry targets should have ExceptionProcessor.

So can both override/replace/reject the exception and send extra data to the exception for its scope.

You can use beforeSend callback for this.


        SentrySDK.start { options in

            options.dsn = dsn

            options.beforeSend = { event in

                return event

            }

        }

This is the EventProcessor, not the same thing.

You can't read/replace original exception.

barisyild avatar Jul 18 '24 13:07 barisyild

I think all sentry targets should have ExceptionProcessor.

So can both override/replace/reject the exception and send extra data to the exception for its scope.

You can use beforeSend callback for this.


        SentrySDK.start { options in

            options.dsn = dsn

            options.beforeSend = { event in

                return event

            }

        }

This is the EventProcessor, not the same thing.

You can't read/replace original exception.

Moreover, this works at event level, the structure I mentioned will work at scope level.

barisyild avatar Jul 18 '24 13:07 barisyild

More information shared at https://discord.com/channels/621778831602221064/1263605605051142204/1263605605051142204

brustolin avatar Jul 19 '24 08:07 brustolin

We can/should solve this using hints, similar to how JS does.

kahest avatar Jul 31 '24 12:07 kahest