Skip to content

Commit 4104a8a

Browse files
authored
Gracefully handle unknown message types (#141)
1 parent a4be58f commit 4104a8a

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.0.0-patch-1] - 2026-03-16
9+
10+
- Gracefully handle unknown message types
11+
812
## [5.0.0] - 2025-08-14
913

1014
- Moved channel field to root of AddTranscript message for multichannel transcription.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.0
1+
5.0.0-patch-1

speechmatics/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,15 @@ def _consumer(self, message):
255255
message = json.loads(message)
256256
message_type = message["message"]
257257

258-
for handler in self.event_handlers[message_type]:
259-
try:
260-
handler(copy.deepcopy(message))
261-
except ForceEndSession:
262-
LOGGER.warning("Session was ended forcefully by an event handler")
263-
raise
258+
try:
259+
for handler in self.event_handlers[message_type]:
260+
try:
261+
handler(copy.deepcopy(message))
262+
except ForceEndSession:
263+
LOGGER.warning("Session was ended forcefully by an event handler")
264+
raise
265+
except KeyError as kex:
266+
LOGGER.debug(f"Unknown handler for message type: {message_type} {kex=}")
264267

265268
if message_type == ServerMessageType.RecognitionStarted:
266269
self._flag_recognition_started()

0 commit comments

Comments
 (0)