From: Christian Heller Date: Wed, 8 Oct 2025 22:23:04 +0000 (+0200) Subject: Catch _all_ Client.send fails. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/todo?a=commitdiff_plain;h=a836d3c3e55f40d07b54231d03488e82302eff08;p=ircplom Catch _all_ Client.send fails. --- diff --git a/src/ircplom/client.py b/src/ircplom/client.py index 6d29e0f..6794583 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -931,7 +931,7 @@ class Client(ABC, ClientQueueMixin): def _alert(self, msg: str) -> None: pass - def send(self, verb: str, *args) -> IrcMessage: + def send(self, verb: str, *args) -> Optional[IrcMessage]: 'Send msg over socket, on success log .raw.' if not self.conn: raise SendFail('cannot send, connection seems closed') diff --git a/src/ircplom/client_tui.py b/src/ircplom/client_tui.py index 7b51350..7c0a4c4 100644 --- a/src/ircplom/client_tui.py +++ b/src/ircplom/client_tui.py @@ -494,14 +494,10 @@ class ClientKnowingTui(Client): def privmsg(self, chat_target: str, msg: str) -> None: 'Catch /privmsg, only allow for channel if in channel, else complain.' - try: - if self.db.is_chan_name(chat_target)\ - and chat_target not in self.db.channels.keys(): - raise SendFail('not sending, since not in channel') - self.send('PRIVMSG', chat_target, msg) - except SendFail as e: - self._tui_alert_trigger(f'{e}') - else: + if self.db.is_chan_name(chat_target)\ + and chat_target not in self.db.channels.keys(): + self._tui_alert_trigger('not sending, since not in channel') + elif self.send('PRIVMSG', chat_target, msg): self.db.messaging('').to(chat_target).privmsg = msg # type: ignore def reconnect(self) -> None: @@ -512,8 +508,13 @@ class ClientKnowingTui(Client): return self.connect() - def send(self, verb: str, *args) -> IrcMessage: - msg = super().send(verb, *args) + def send(self, verb: str, *args) -> Optional[IrcMessage]: + try: + msg = super().send(verb, *args) + except SendFail as e: + self._tui_alert_trigger(f'{e}') + return None + assert msg is not None self._log(msg.raw, out=True) return msg