Skip to content

fix(tts): don't re-raise a send TTSError the with block already caught - #318

Open
gshost1 wants to merge 1 commit into
AssemblyAI:masterfrom
gshost1:fix/tts-send-error-raised-twice
Open

gshost1 wants to merge 1 commit into
AssemblyAI:masterfrom
gshost1:fix/tts-send-error-raised-twice

Conversation

@gshost1

@gshost1 gshost1 commented Nov 27, 2026

Copy link
Copy Markdown

Fixes #317.

When a send (generate(), flush(), cancel(), keep_alive()) hit a socket the server had closed, _closed_error() returned the session error without marking it as raised. A block that caught that TTSError still had it raised again from __exit__ / __aexit__.

Changes:

  • assemblyai/tts/v1/session.py, assemblyai/tts/v1/async_session.py: _closed_error() returns self._surfaced() instead of self.error. One line each.
  • Tests in tests/unit/test_tts_session.py and tests/unit/test_tts_session_async.py: an error frame (3010) and a bare close (1012) caught inside with / async with are raised once.
  • A guard test: a send from a FlushDone handler after a 1012 close still raises on exit, because _emit() swallows handler exceptions and the block never saw it.

How tested: the 4 new cases fail on master and pass with the fix. The guard test passes on both. pytest tests: 1039 passed (master: 1034). ruff format --check, ruff check, mypy clean.

_closed_error() returned self.error without marking it surfaced, unlike
every other path that hands the error to the caller. A block that caught
a TTSError from generate()/flush()/cancel()/keep_alive() after the server
closed the socket had the same error raised again from __exit__.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTSSession raises a send TTSError a second time on leaving the with block, after the block already caught it

1 participant