Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exceptions cause sessions to be marked as crashed #1721

Open
WeiLingQiang opened this issue Jul 10, 2024 · 10 comments
Open

Unhandled exceptions cause sessions to be marked as crashed #1721

WeiLingQiang opened this issue Jul 10, 2024 · 10 comments

Comments

@WeiLingQiang
Copy link

          ![image](https://github.com/getsentry/sentry-unity/assets/103353466/270f6162-aae1-423f-84f4-1c585d905480)

There is an error:
I throw an exception: throw new InvalidOperationException("xxx")
It is considered a crashed,
Shouldn't it be an errored ?

Originally posted by @WeiLingQiang in #1707 (comment)

@WeiLingQiang
Copy link
Author

          ![image](https://github.com/getsentry/sentry-unity/assets/103353466/270f6162-aae1-423f-84f4-1c585d905480)

There is an error: I throw an exception: throw new InvalidOperationException("xxx") It is considered a crashed, Shouldn't it be an errored ?

Originally posted by @WeiLingQiang in #1707 (comment)

image

@bitsandfoxes
Copy link
Contributor

Good catch!
The SDK considers sessions that had unhandled exceptions happen as crashed as opposed to errored right now. But I get that within the context of a Unity game where Unity prevents the game from actually crashing based on an exception, this might be confusing.

@WeiLingQiang
Copy link
Author

Thanks, What should I do if I want to count actual crashes in Unity games? And count the crash rate

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 12, 2024
@WeiLingQiang
Copy link
Author

had unhandled exceptions happen

Because an unhandled exception occurs, the game will not actually crash

@bitsandfoxes
Copy link
Contributor

What the SDK could do is to add to the mechanism type to basically filter exceptions.
The only workaround for you, to unblock yourself, that I can see right now is to set the Exception.Data[Mechanism.HandledKey] = true in the BeforeSend callback.

@bitsandfoxes
Copy link
Contributor

For what it's worth, we've had a very long discussion about resolving this (indirectly) in an RCF.

@WeiLingQiang
Copy link
Author

WeiLingQiang commented Jul 17, 2024

Excuse me, is there a solution?

What the SDK could do is to add to the mechanism type to basically filter exceptions. The only workaround for you, to unblock yourself, that I can see right now is to set the Exception.Data[Mechanism.HandledKey] = true in the BeforeSend callback.

options.SetBeforeSend((sentryEvent, _) => {
    if (sentryEvent.Exception != null) {
        sentryEvent.Exception.SetSentryMechanism("error", "UnityException", true);
        sentryEvent.Exception.Data[Mechanism.HandledKey] = true;
    }
    return sentryEvent;
});

I set BeforeSend but it still doesn't work, help me !

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 17, 2024
@WeiLingQiang
Copy link
Author

image

@bitsandfoxes
Copy link
Contributor

Apologies for the delay. The mechanism is not the one on the actual exception-object but on the SentryException. Again, I don't recommend doing it that way but if you've got a valid usecase then it could look like this:

options.SetBeforeSend((sentryEvent, _) => {
    if (sentryEvent.Exception != null) {
        sentryEvent.SentryExceptions.FirstOrDefault().Mechanism.Handled = true;
    }
    return sentryEvent;
});

@bitsandfoxes bitsandfoxes changed the title Dashboard count crash rates, Error Unhandled exceptions cause sessions to be marked as crashed Jul 29, 2024
@WeiLingQiang
Copy link
Author

Thanks, this helps me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Status: No status
Development

No branches or pull requests

3 participants