Skip to content

Commit a59729f

Browse files
Add Exception HResult to mechanism data (#4029)
--------- Co-authored-by: James Crosswell <[email protected]>
1 parent 90ee8b1 commit a59729f

15 files changed

+96
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Exception.HResult is now included in the mechanism data for all exceptions ([#4029](https://github.com/getsentry/sentry-dotnet/pull/4029))
8+
59
### Dependencies
610

711
- Bump CLI from v2.42.2 to v2.42.3 ([#4036](https://github.com/getsentry/sentry-dotnet/pull/4036))

src/Sentry/Internal/MainExceptionProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ private static Mechanism GetMechanism(Exception exception, int id, int? parentId
199199
exception.Data.Remove(Mechanism.DescriptionKey);
200200
}
201201

202+
// Add HResult to mechanism data before adding exception data, so that it can be overridden.
203+
mechanism.Data["HResult"] = $"0x{exception.HResult:X8}";
204+
202205
// Copy remaining exception data to mechanism data.
203206
foreach (var key in exception.Data.Keys.OfType<string>())
204207
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
SentryExceptions: [
1111
{
1212
Type: System.Exception,
13-
Value: my exception
13+
Value: my exception,
14+
Mechanism: {
15+
Type: generic,
16+
Synthetic: false,
17+
IsExceptionGroup: false,
18+
Data: {
19+
HResult: 0x80131500
20+
}
21+
}
1422
}
1523
],
1624
Level: error,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet9_0.verified.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
SentryExceptions: [
1111
{
1212
Type: System.Exception,
13-
Value: my exception
13+
Value: my exception,
14+
Mechanism: {
15+
Type: generic,
16+
Synthetic: false,
17+
IsExceptionGroup: false,
18+
Data: {
19+
HResult: 0x80131500
20+
}
21+
}
1422
}
1523
],
1624
Level: error,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
SentryExceptions: [
1111
{
1212
Type: System.Exception,
13-
Value: my exception
13+
Value: my exception,
14+
Mechanism: {
15+
Type: generic,
16+
Synthetic: false,
17+
IsExceptionGroup: false,
18+
Data: {
19+
HResult: 0x80131500
20+
}
21+
}
1422
}
1523
],
1624
Level: error,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
SentryExceptions: [
1111
{
1212
Type: System.Exception,
13-
Value: my exception
13+
Value: my exception,
14+
Mechanism: {
15+
Type: generic,
16+
Synthetic: false,
17+
IsExceptionGroup: false,
18+
Data: {
19+
HResult: 0x80131500
20+
}
21+
}
1422
}
1523
],
1624
Level: error,

test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
SentryExceptions: [
1111
{
1212
Type: System.Exception,
13-
Value: my exception
13+
Value: my exception,
14+
Mechanism: {
15+
Type: generic,
16+
Synthetic: false,
17+
IsExceptionGroup: false,
18+
Data: {
19+
HResult: 0x80131500
20+
}
21+
}
1422
}
1523
],
1624
Level: error,

test/Sentry.NLog.Tests/IntegrationTests.Simple.DotNet8_0.verified.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
Type: generic,
6060
Handled: true,
6161
Synthetic: false,
62-
IsExceptionGroup: false
62+
IsExceptionGroup: false,
63+
Data: {
64+
HResult: 0x80131500
65+
}
6366
}
6467
}
6568
],

test/Sentry.NLog.Tests/IntegrationTests.Simple.DotNet9_0.verified.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
Type: generic,
6060
Handled: true,
6161
Synthetic: false,
62-
IsExceptionGroup: false
62+
IsExceptionGroup: false,
63+
Data: {
64+
HResult: 0x80131500
65+
}
6366
}
6467
}
6568
],

test/Sentry.NLog.Tests/IntegrationTests.Simple.Mono4_0.verified.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
Type: generic,
6060
Handled: true,
6161
Synthetic: false,
62-
IsExceptionGroup: false
62+
IsExceptionGroup: false,
63+
Data: {
64+
HResult: 0x80131500
65+
}
6366
}
6467
}
6568
],

0 commit comments

Comments
 (0)