-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[NET] Use SetCurrentStackTrace for not thrown exceptions #117802
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances stack trace information for not-thrown exceptions in networking libraries by using ExceptionDispatchInfo.SetCurrentStackTrace()
. This helps improve debugging by providing better stack traces when exceptions are created but wrapped in Task.FromException
or ValueTask.FromException
rather than being directly thrown.
- Applies
ExceptionDispatchInfo.SetCurrentStackTrace()
to exceptions used withValueTask.FromException
andTask.FromException
- Adds necessary
using System.Runtime.ExceptionServices;
statements where needed - Updates exception creation patterns to preserve stack trace information for better debugging
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
WebSocketStream.cs | Wraps NotSupportedException and ObjectDisposedException instances with SetCurrentStackTrace |
ManagedWebSocket.cs | Applies SetCurrentStackTrace to WebSocketException and OperationCanceledException |
Socket.Tasks.cs | Wraps NotSupportedException with SetCurrentStackTrace |
SocketsHttpHandler.cs | Applies SetCurrentStackTrace to various HTTP-related exceptions |
Http3RequestStream.cs | Wraps ObjectDisposedException instances with SetCurrentStackTrace |
Http2Stream.cs | Applies SetCurrentStackTrace to NotSupportedException, HttpRequestException, and ObjectDisposedException |
Http2Connection.cs | Wraps ObjectDisposedException and IOException with SetCurrentStackTrace |
ContentLengthWriteStream.cs | Applies SetCurrentStackTrace to HttpRequestException instances |
HttpContent.cs | Wraps HttpRequestException instances with SetCurrentStackTrace |
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Fixes #117652