You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some exceptions, especially COMException or Win32Exception, sometimes do not provide a good exception message which makes it hard to analyze issues on Sentry. COMException even often returns an empty exception message.
However, in .NET every Exception object has a HResult property. Especially for the cases mentioned above, this value would be worth a lot as it contains the concrete error type (e.g. -2147417842 -> RPC_E_WRONG_THREAD). This HResult property is currently not sent with a Sentry event.
Therefore I would like to request the HResult property of an Exception to also be uploaded in a SentryEvent, and that its value is also visible in the Sentry web UI.
However, there are currently only Linux/Apple specific definitions listed, like signal or mach_exception. A definition for a Windows HResult, or more generally HResult (as they may also be used in cross-platform .NET apps), should be added there.
Using ISentryEventExceptionProcessor I already tried manually adding some HResult field to the Meta. However, it was not displayed in the Sentry web UI. Only when I used errno to "fake" a HResult, it was showing up. So I assume you must also add server-side handling.
For the .NET side, the change should be fairly easy. In the MainExceptionProcessor, something alike should be added:
Thanks for the suggestion @whiskhub - it's a good idea!
In the mean time, you could easily write your own processor to add this information to events:
internalclassComExceptionProcessor:ISentryEventExceptionProcessor{publicvoidProcess(Exceptionexception,SentryEventsentryEvent){// Add the HResult to the event's extra data.sentryEvent.SetExtra("HResult",exception.HResult);}}
... and then use this when initialising Sentry:
SentrySdk.Init(options =>{// All your normal options// Wire up the custom event processoroptions.AddExceptionProcessor(newComExceptionProcessor());});
@jamescrosswell If the COMException is aggregated or is a inner exception, then your code will failed to handle them.
And if there are multiple COMExceptions in the parent exception, and they may have different HResult values. I think get only the parent's hresult is not enough for WinUI 3 or WinRT.
So the HResult needs to be stored on the SentryException rather than the SentryEvent (or it needs to be stored on the event in a convoluted way that lets you know which exception it relates to)... So back to what @whiskhub suggested - the UI needs to be able to display this if it is stored in the Mechanism metadata basically.
I think it makes sense to add this OOTB. Sentry could even link to the right place if that's helpful too. Or have some mappigns in the server so the UI shows additional context other than just the codes
@Lightczx would you be willing to add a PR to the repo with this feature?
Not sure about .ZIp as the approach, but conceptually I agree that any HResult in an exception should be added to the Sentry exception, so it shows up as it did on your screenshot
Activity
jamescrosswell commentedon Feb 5, 2025
Thanks for the suggestion @whiskhub - it's a good idea!
In the mean time, you could easily write your own processor to add this information to events:
... and then use this when initialising Sentry:
Lightczx commentedon Mar 4, 2025
@jamescrosswell If the COMException is aggregated or is a inner exception, then your code will failed to handle them.
And if there are multiple COMExceptions in the parent exception, and they may have different HResult values. I think get only the parent's hresult is not enough for WinUI 3 or WinRT.
jamescrosswell commentedon Mar 4, 2025
Good call @Lightczx.
Sentry unpacks aggregate exceptions and will show multiple exceptions (where appropriate) for a single event...
So the HResult needs to be stored on the
SentryExceptionrather than theSentryEvent(or it needs to be stored on the event in a convoluted way that lets you know which exception it relates to)... So back to what @whiskhub suggested - the UI needs to be able to display this if it is stored in the Mechanism metadata basically.bruno-garcia commentedon Mar 4, 2025
I think it makes sense to add this OOTB. Sentry could even link to the right place if that's helpful too. Or have some mappigns in the server so the UI shows additional context other than just the codes
4 remaining items
bruno-garcia commentedon Mar 7, 2025
@Lightczx would you be willing to add a PR to the repo with this feature?
Not sure about
.ZIpas the approach, but conceptually I agree that anyHResultin an exception should be added to the Sentry exception, so it shows up as it did on your screenshotLightczx commentedon Mar 8, 2025
I can make a PR to adjust the MainExceptionProcessor, then no .Zip() call needed, HResult can just set here.
But I was also thinking, should we provide an option to disable the new behavior? @bruno-garcia
impl getsentry#3939