-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Consider Mechanism.Handled
for non-thrown captured exceptions
#3383
Comments
Mechanism.Handled
Mechanism.Handled
for non-thrown captured exceptions
We should consider other scenarios where the stacktrace ends up being |
it feels to me like the only entity who knows for sure if an exception sent to |
It's possible for the caller to set handled to true/false by setting the "mechanism" for the exception before capturing it... which is how the Sentry middleware sets this in the ASP.NET Core integration:
It looks like the main exception processor would overwrite any value that was set explicitly via the mechanism though... which probably isn't a good idea. If someone has set this mechanism explicitly, we shouldn't be overwriting it right? |
Yeah, definitely not! |
Is that even documented in the SDK docs site? Either way, it just seems like it would be a lot user-friendlier and more discoverable to offer a new overload: |
If a user captures an exception via |
That rings true... and more reliable than checking whether there is a stack trace or not. |
@bitsandfoxes do you mean semantically? or are you talking about the implementation |
If a user calls A bit of a problem with the During capture, the but hub and client check whether the event was sentry-dotnet/src/Sentry/Internal/Hub.cs Lines 439 to 445 in 34cd01c
sentry-dotnet/src/Sentry/SentryClient.cs Lines 334 to 346 in 34cd01c
sentry-dotnet/src/Sentry/SentryEvent.cs Lines 183 to 197 in 34cd01c
Now in the case of i.e. Unity where an unhandled exception does not crash the game the session still gets updated as So ideally
|
I think all of that makes sense... just one question:
@bitsandfoxes what would be the alternative mechanism to determine this? |
That I don't know. But maybe we can leverage one of the |
🤔 I think those are only available on Unix derivatives... so we'd need some other mechanism for non *nix [as well]. |
@bitsandfoxes re this statement:
IMO this is not correct. Only the code author that called In my mind there are two possible scenarios for situations where app code authors call
|
@ericsampson the comment I made on your PR relates to this. I think my comment above was not very clear... it's not the middleware that I was worried about but this: sentry-dotnet/src/Sentry/Internal/MainExceptionProcessor.cs Lines 177 to 188 in d1e5efc
I'm not 100% sure whether it's an issue or not. I think we'd need to confirm with some sample that demonstrated a problem before we try to fix it. |
I'm very confused.
But there is a key check already happening in the lines just before the ones that were posted previously in this thread. It's already first checking the value of sentry-dotnet/src/Sentry/Internal/MainExceptionProcessor.cs Lines 171 to 188 in c892db4
|
Indeed, and there's a comment there:
So basically, that code is preserving any mechanism information if it has already been set on the exception. That bit I think is fine... Reading the code again though, my initial concern about it overriding the mechanism was unfounded. The The else statements seem a bit more random. If no mechanism has been set on the exception, the code seems to make assumptions about whether the exception was handled or not based on the presence/absence of a stack trace in the exception... All of which I think takes us back to what @bitsandfoxes originally summarised (quite well, and without all the confusion that I added - apologies for that). |
right, that's all I was trying to do was to get us back in sync with the correct state :) I'd propose that the code be simplified to just the following:
|
So the only time we'd end up in the @bitsandfoxes I think that's what you had in mind when you created this ticket right? I'm OK with that. I think the only credible alternative would be if we defaulted I'm fine with either option. Maybe worth adding a code comment to explain the reasoning, one way or the other. |
Much appreciated and thanks for bearing with us... working out what we're supposed to do is often over 50% of the work! |
I think it's more about matching the Sentry intent than end-user expectations, to maintain consistency across the various SDKs. https://develop.sentry.dev/sdk/event-payloads/exception/#exception-mechanism
This is probably the best source of documentation about the intent that I can find, which seems to support setting it to handled: Annotated<bool> This is a best-effort guess at whether the exception was handled by user code or not. For example: Exceptions leading to a 500 Internal Server Error or to a hard process crash are handled=false, as the SDK typically has an integration that automatically captures the error. |
This sounds right to me. Thanks a lot for sifting through our docs! |
The
MainExceptionProcessor
handles setting the mechanism here:sentry-dotnet/src/Sentry/Internal/MainExceptionProcessor.cs
Lines 177 to 188 in c30052e
So this code ends up with
Handled = true
And this code ends up with
Handled --
in the issue'sHighlights
Interestingly, captured messages are
Handled --
too.Which, personally, I find confusing. If an exception is not
unhandled
, should we not consider ithandled
implicitly? I'm not talking technical correctness here but user expectations.But I can still filter issues based on
error.handled:false
so maybe it doesn't matter?The text was updated successfully, but these errors were encountered: