Skip to content

Commit 4b4e2fb

Browse files
PaulAsjesclaude
andcommitted
Guard against non-dict JSON messages in the receive loop
json.loads can return lists, strings, numbers, or null. These would crash _handle_message which expects a dict. Now emits an error event and continues instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4cefffe commit 4b4e2fb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/elevenlabs/speech_engine/session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ async def run(self) -> None:
253253
await self._emit("error", e)
254254
continue
255255

256+
if not isinstance(msg, dict):
257+
await self._emit(
258+
"error",
259+
ValueError(f"expected JSON object, got {type(msg).__name__}"),
260+
)
261+
continue
262+
256263
await self._handle_message(msg)
257264
except asyncio.CancelledError:
258265
raise

0 commit comments

Comments
 (0)