Fix stream error handlers raising a tuple instead of an exception - #447
Open
dylanpulver wants to merge 1 commit into
Open
Fix stream error handlers raising a tuple instead of an exception#447dylanpulver wants to merge 1 commit into
dylanpulver wants to merge 1 commit into
Conversation
The ReadTimeout and ConnectionError handlers in StreamListener.handle_stream
ended the constructor call with a trailing comma, so `exception` was a 1-tuple.
`raise exception from err` therefore raised
TypeError: exceptions must derive from BaseException
and on_abort was handed the tuple instead of the exception object its docstring
documents.
This also broke auto-reconnect: Mastodon.__stream catches (AttributeError,
MastodonMalformedEventError, MastodonNetworkError) to decide whether to
reconnect, and TypeError is not in that tuple, so a read timeout or connection
reset terminated the streaming thread.
Reported in halcy#368 and closed as presumed fixed by dropping six; dropping six
turned six.raise_from(tuple, err) into `raise tuple from err`, which fails
identically. The ChunkedEncodingError branch never had the comma.
Adds a test covering all three transport error branches.
Owner
|
Thank you, good catch, I will have a look at it when I have some more bandwidth |
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.
streaming.pylines 160 and 165 terminate theMastodonReadTimeout(...)/MastodonNetworkError(...)constructor call with a trailing comma, soexceptionis a 1-tuple.raise exception from errthen raisesTypeError: exceptions must derive from BaseException, andon_abortreceives the tuple rather than the exception object its docstring promises (streaming.py:86-95).Knock-on effect:
__streamcatches(AttributeError, MastodonMalformedEventError, MastodonNetworkError)at internals.py:555 to drivereconnect_async.TypeErroris not in that tuple, so a read timeout or a connection reset kills the streaming thread instead of reconnecting.This is #368. It was closed on the theory that
sixwas responsible; removingsixin 945e8e6 turnedsix.raise_from(tuple, err)intoraise tuple from err, which fails the same way. TheChunkedEncodingErrorbranch never had the comma, which is likely why the #323 fix looked complete.Measured with a stub response whose
iter_contentraises: before,ReadTimeoutandConnectionErrorboth giveTypeErrorand handon_aborta tuple; after, they giveMastodonReadTimeout/MastodonNetworkErrorwith__cause__set.ChunkedEncodingErroris unchanged in both. Full suite went 522 passed / 18 skipped / 4 xfailed to 525 / 18 / 4 on Python 3.14, macOS.Not tested: no live stream and no real socket timeout. The new test calls
handle_streamdirectly, and the__streamreconnect consequence is read off the except clause rather than exercised.Claude Code was used to locate and patch this.