Fix exceptions in websocket receive_* methods#9511
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #9511 +/- ##
==========================================
+ Coverage 98.65% 98.66% +0.01%
==========================================
Files 116 116
Lines 35482 35526 +44
Branches 4211 4215 +4
==========================================
+ Hits 35003 35051 +48
+ Misses 321 319 -2
+ Partials 158 156 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
But, should we use a connection error instead of RuntimeError as suggested by someone in that issue? That would make it easier for someone to catch the exception, as TypeError/RuntimeError is not really obvious. @bdraco Any opinions on the exception? |
|
Changing it from |
Should the new exception be included in the |
I think one in |
|
@bdraco updated with the suggested changes. I have added the exception in just |
|
Would you please update the change log message and the opening text as well to reflect the most recent changes |
CodSpeed Performance ReportMerging #9511 will not alter performanceComparing Summary
|
|
@bdraco updated. Please have a look |
|
It looks like there are 4 lines that need test coverage. Thanks |
|
@bdraco I have completed tests for these changes |
|
There might still be 2 uncovered lines showing up in the report, but they are not a part of the changes done in this PR and just include formatting changes. Let me know if you need me to add tests for those as well. Thanks |
|
The object paths can be a bit tricky. Check CHANGES.rst for previous usage to figure them out |
|
Once it's all passing check the read the docs preview as it will show how it will appear in the changelog |
|
Fixed the changelog refs and also made some changes to the docs. I had to add documentation for the Additionally, can you please guide me about how where this exception should be added in the aiohttp/docs/client_reference.rst Lines 2346 to 2355 in 3f4f3ad |
I will take a look as soon as I can. Ran out of time for today. |
asvetlov
left a comment
There was a problem hiding this comment.
Please don't merge until tomorrow. I need more time to review the PR. Thanks
Co-authored-by: J. Nick Koston <[email protected]>
|
Not sure if |
|
@bdraco please feel free to merge if you have no objections. |
|
Will run through it later today. Thanks |
|
Also @bdraco, I was thinking if it would be a good idea to add the websocket message-type and optionally data information in the exception class so that the end users can use those if required: raise WSMessageTypeError(
f"Received message {msg.type}:{msg.data!r} is not WSMsgType.TEXT", received_msg_type=msg.type, received_msg_data=data,
|
|
I'd worry a bit about storing a strong reference the whole payload in the Exception as Exceptions tend to get logged and collected by various systems which may have some undesirable memory impact |
|
Let's not expand the scope of this PR. We can consider other changes in a followup |
Backport to 3.11: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 75ae623 on top of patchback/backports/3.11/75ae6236547f78fce9debb3788407311a7b8ecbb/pr-9511 Backporting merged PR #9511 into master
🤖 @patchback |
Co-authored-by: J. Nick Koston <[email protected]> (cherry picked from commit 75ae623)
|
backport #9676 |
…_* methods (#9676) Co-authored-by: J. Nick Koston <[email protected]> Co-authored-by: ara-25 <[email protected]>

What do these changes do?
WSMessageTypeErrorexceptionWSMessageTypeErrorexception inreceive_*methods inWebSocketResponseandClientWebSocketResponse, when message without any content is received.Are there changes in behavior for the user?
Websocket
receive_strandreceive_bytesmethods will now raiseWSMessageTypeError, instead ofTypeError, when websocket messages without content are received.Is it a substantial burden for the maintainers to support this?
No
Related issue number
Fixes #6800
Checklist
CONTRIBUTORS.txtCHANGES/folder