Improve WebSocket exceptions to include informative messages#129428
Open
Copilot wants to merge 2 commits into
Open
Improve WebSocket exceptions to include informative messages#129428Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
MihaZupan
June 15, 2026 15:25
View session
MihaZupan
approved these changes
Jun 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves diagnostic quality in System.Net.WebSockets by ensuring protocol/UTF-8 receive failures throw WebSocketException instances with informative, scenario-specific messages (instead of falling back to a generic “Aborted state” message with no inner exception).
Changes:
- Updates
ManagedWebSocketreceive/close error paths to pass explicit resource-based error messages intoCloseWithReceiveErrorAndThrowAsync. - Adds new
SRstring resources for invalid UTF-8 text payload, protocol violation, invalid close status code, and invalid close description UTF-8. - Adds/updates tests to validate the new exception messages for invalid UTF-8 and malformed close frames.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Net.WebSockets/tests/WebSocketUtf8Tests.cs | Asserts the new invalid-UTF8 payload exception message in existing UTF-8 validation tests. |
| src/libraries/System.Net.WebSockets/tests/WebSocketReceiveErrorMessageTests.cs | New tests that synthesize invalid frames and validate WebSocketException.Message / InnerException. |
| src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj | Includes the new test file in the test project compilation list. |
| src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs | Supplies explicit error messages for invalid UTF-8 payload and malformed close payload scenarios. |
| src/libraries/System.Net.WebSockets/src/Resources/Strings.resx | Adds new localized resource strings used by the improved exceptions. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Open
3 tasks
rzikm
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #129192
Adds error messages for cases like receiving a text message that's not valid UTF-8, an invalid close status code / description.
The current behavior was an exception like
where there'd be no inner exception to inspect.