From 897c5b1f6c9c5cb7154db5b4ae3ab3a4902ef15a Mon Sep 17 00:00:00 2001 From: Username Date: Tue, 24 Feb 2026 16:23:05 +0100 Subject: [PATCH] client: guard join_channel and send_text against stale ids join_channel raises ValueError on missing channel instead of KeyError. send_text handles missing channel_id gracefully. --- src/tuimble/client.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tuimble/client.py b/src/tuimble/client.py index 056cf7c..aab854a 100644 --- a/src/tuimble/client.py +++ b/src/tuimble/client.py @@ -229,7 +229,12 @@ class MumbleClient: def send_text(self, message: str): """Send a text message to the current channel.""" if self._mumble and self._connected: - ch = self._mumble.channels[self._mumble.users.myself["channel_id"]] + try: + cid = self._mumble.users.myself["channel_id"] + ch = self._mumble.channels[cid] + except (KeyError, AttributeError): + log.warning("send_text: channel unavailable") + return ch.send_text_message(message) def send_audio(self, pcm_data: bytes): @@ -238,9 +243,16 @@ class MumbleClient: self._mumble.sound_output.add_sound(pcm_data) def join_channel(self, channel_id: int): - """Move to a different channel.""" + """Move to a different channel. + + Raises: + ValueError: If the channel no longer exists on the server. + """ if self._mumble and self._connected: - self._mumble.channels[channel_id].move_in() + ch = self._mumble.channels.get(channel_id) + if ch is None: + raise ValueError(f"channel {channel_id} not found") + ch.move_in() def set_self_deaf(self, deaf: bool): """Toggle self-deafen on the server."""