Preserve underlying error when InternetSource fails to decode#2857
Open
balloob wants to merge 6 commits into
Open
Preserve underlying error when InternetSource fails to decode#2857balloob wants to merge 6 commits into
balloob wants to merge 6 commits into
Conversation
When streaming over HTTP via RAOP, the PatchedIceCastClient download thread captured exceptions as strings and logged them at DEBUG level, and InternetSource.open only inspected that string without waiting for the download thread to finish. If miniaudio raised DecodeError before the download thread had recorded its error, the real cause (e.g. HTTP 401, connection error, timeout) was discarded and the caller only saw "failed to init decoder". Store the actual exception, wait for the download thread to settle on DecodeError, and chain the original exception via "raise ... from" so the underlying cause is preserved in tracebacks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
|
@balloob flake8 issue is flaking out |
NorbertHD
reviewed
May 28, 2026
This was referenced Jun 2, 2026
Co-authored-by: Quentame <polletquentin74@me.com>
Quentame
reviewed
Jun 2, 2026
Co-authored-by: Quentame <polletquentin74@me.com>
Refactor error handling in audio source decoding.
Author
|
@postlund could we get a release with this fix? |
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.
Summary
When streaming over HTTP via RAOP, the underlying error that caused a stream to fail was being swallowed. Users only saw
miniaudio.DecodeError: ('failed to init decoder', -1)with no hint of the real cause (HTTP 401, connection error, timeout, etc.).Two issues in
pyatv/protocols/raop/audio_source.py:PatchedIceCastClient._stream_wrappercaptured download exceptions asstr(ex)and logged them at DEBUG. The actual exception type and traceback were lost.InternetSource.opencheckedsource.error_messageimmediately afterminiaudio.stream_anyraisedDecodeError, racing the download thread. If miniaudio failed before the download thread had recorded its error, the real cause was discarded and only theDecodeErrorpropagated.Changes
source.error: Optional[BaseException]) instead of a string, and log it at WARNING.DecodeError, explicitly close the source first (joining the download thread) so any HTTP/network error is captured before we inspect it.ProtocolError(...) from source.errorso the original cause is preserved in the traceback chain.If the URL truly returns valid audio that miniaudio can't decode, the
DecodeErroris still re-raised unchanged.Motivation
This helps diagnose issues like home-assistant/core#169164 where the actual cause (e.g. an HTTP error from the media source) was masked by a generic
failed to init decodermessage.🤖 Generated with Claude Code