Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve approach to not use an Inner exception per PR feedback.
  • Loading branch information
ericsampson committed Nov 24, 2025
commit c3faef84cdfc5dce2f2a855f434b830bada61949
12 changes: 6 additions & 6 deletions src/Sentry/SentryGraphQLHttpFailedRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ protected internal override void DoEnsureSuccessfulResponse([NotNull] HttpReques
var exception = new GraphQLHttpRequestException(errorMessage);

#if NET5_0_OR_GREATER
// Add a full stack trace into the exception to improve Issue grouping,
// see https://github.com/getsentry/sentry-dotnet/issues/3582
ExceptionDispatchInfo.SetCurrentStackTrace(exception);
// Add a full stack trace into the exception to improve Issue grouping,
// see https://github.com/getsentry/sentry-dotnet/issues/3582
ExceptionDispatchInfo.Throw(ExceptionDispatchInfo.SetCurrentStackTrace(exception));
#else
// Where SetCurrentStackTrace is not available, just throw the Exception
throw exception;
#endif
// Wrap in a new exception to preserve the stack trace when thrown and caught.
// The inner exception will have the full stack trace for better issue grouping.
throw new GraphQLHttpRequestException(errorMessage, exception);
}
}
// No GraphQL errors, but we still might have an HTTP error status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ public void HandleResponse_Error_CaptureRequestAndResponse()
// Ensure it's a GraphQL exception (not HTTP fallback)
@event.Exception.Should().BeOfType<GraphQLHttpRequestException>();
@event.Exception!.Message.Should().Be(DefaultErrorMessage);
@event.Exception!.InnerException.Should().NotBeNull("inner exception should have the stack trace");
@event.Exception!.InnerException.Should().BeOfType<GraphQLHttpRequestException>();
@event.Exception!.InnerException!.Message.Should().Be(DefaultErrorMessage);

// Ensure the mechanism is set
@event.Exception?.Data[Mechanism.MechanismKey].Should().Be(SentryGraphQLHttpFailedRequestHandler.MechanismType);
Expand Down Expand Up @@ -330,10 +327,9 @@ public void HandleResponse_GraphQLError_ExceptionStackTraceHasCallerContext()
{
@event.Should().NotBeNull();
@event.Exception.Should().NotBeNull();
@event.Exception!.InnerException.Should().NotBeNull();

// Inner exception's stack trace should include this test method name, proving we captured caller context on .NET 5+
@event.Exception!.InnerException!.StackTrace.Should().Contain(nameof(HandleResponse_GraphQLError_ExceptionStackTraceHasCallerContext));
// Exception's stack trace should include this test method name, proving we captured caller context on .NET 5+
@event.Exception!.StackTrace.Should().Contain(nameof(HandleResponse_GraphQLError_ExceptionStackTraceHasCallerContext));
}
}
#endif
Expand Down
Loading