Skip to content
This repository was archived by the owner on Jun 29, 2026. It is now read-only.

fix: narrow except TypeError to only catch websockets version mismatch - #1

Open
AmSach wants to merge 1 commit into
mainfrom
fix/typeerror-exception-masking
Open

AmSach wants to merge 1 commit into
mainfrom
fix/typeerror-exception-masking

Conversation

@AmSach

@AmSach AmSach commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Fixed the bug described in issue googleapis#794. Here is what was wrong and how I fixed it:

The Problem:
The except TypeError block in live.py and live_music.py was catching ALL TypeErrors, including unrelated ones from caller code. When a newer websockets library version is used, TypeErrors can come from the caller's API (e.g., extra_headers vs additional_headers mismatch), but the broad catch made these look like version-compatibility issues. This masked real errors, made debugging harder, and caused the fallback path to trigger when it should not.

The Fix:
Changed the broad except TypeError: to a conditional check that only catches TypeErrors specifically related to the decode= keyword argument introduced in websockets 14.0+. The pattern:

except TypeError as e:
if decode in str(e):
# Fall back to older websockets API
else:
raise # Re-raise unrelated TypeErrors

This was applied in three places:

  1. AsyncSession._receive() in live.py
  2. AsyncLive.connect() in live.py
  3. AsyncLiveMusic.connect() in live_music.py

Testing by: Verified Python syntax on both modified files. The fix preserves backward compatibility with older websockets while properly surfacing unrelated TypeErrors from caller code.

Closes: googleapis#794

… mismatch

Replace broad 'except TypeError' catches in live.py and live_music.py with
selective checks that only catch TypeErrors related to the 'decode' kwarg
introduced in websockets 14.0+. This prevents masking unrelated TypeErrors
from caller code (e.g., extra_headers vs additional_headers API changes in
newer websockets), making debugging easier and restoring proper error
propagation for other failure modes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError handling in live.py causes compatibility issues with newer websockets library

1 participant