Skip to content

[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

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

ManickaP
Copy link
Member

Fixes #117652

@ManickaP ManickaP requested review from a team and Copilot July 18, 2025 07:01
Copy link
Contributor

@Copilot Copilot AI left a 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 with ValueTask.FromException and Task.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

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ManickaP ManickaP merged commit c2a1045 into dotnet:main Jul 18, 2025
83 of 88 checks passed
@ManickaP ManickaP deleted the exc-st branch July 18, 2025 11:26
@liveans liveans added this to the 10.0.0 milestone Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure stacktrace is always present for ValueTask.FromException in Networking libs
5 participants