home · contact · privacy
Use exception handling on lack of matching server message parser.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 21 Sep 2025 14:58:33 +0000 (16:58 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 21 Sep 2025 14:58:33 +0000 (16:58 +0200)
ircplom/client.py
ircplom/client_tui.py
test.txt

index dec3d2ec4f445fd103b51bd23ee31cbfea9be966..e64b4ca657a8b376ead1a7a19be52d982a9c8b6f 100644 (file)
@@ -21,7 +21,11 @@ _NAMES_DESIRED_SERVER_CAPS = ('sasl',)
 
 
 class SendFail(BaseException):
-    pass
+    'When Client.send fails.'
+
+
+class ImplementationFail(BaseException):
+    'When no matching parser found for server message.'
 
 
 class AutoAttrMixin:
@@ -846,8 +850,7 @@ class Client(ABC, ClientQueueMixin):
                 ret = result
                 break
         if '_verb' not in ret:
-            self._log(f'PLEASE IMPLEMENT HANDLER FOR: {msg.raw}', alert=True)
-            return
+            raise ImplementationFail(f'No handler implemented for: {msg.raw}')
         for n_u_h in ret['_nickuserhosts']:  # update, turn into proper users
             if (id_ := self.db.users.id_for_nickuserhost(
                     n_u_h, allow_none=True, updating=True)):
index ad21878a13cb8a499a7f7702d7c0e611a1628ccd..ec4d0c26cd947a6777988991f71da305c4a2caf7 100644 (file)
@@ -7,8 +7,8 @@ from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window,
                               CMD_SHORTCUTS)
 from ircplom.client import (
         AutoAttrMixin, Channel, Client, ClientQueueMixin, Dict, DictItem,
-        IrcConnSetup, LogScope, NewClientEvent, NickUserHost, SendFail,
-        ServerCapability, SharedClientDbFields, User)
+        ImplementationFail, IrcConnSetup, LogScope, NewClientEvent,
+        NickUserHost, SendFail, ServerCapability, SharedClientDbFields, User)
 from ircplom.irc_conn import IrcMessage
 
 CMD_SHORTCUTS['disconnect'] = 'window.disconnect'
@@ -500,7 +500,10 @@ class ClientKnowingTui(Client):
 
     def handle_msg(self, msg: IrcMessage) -> None:
         self._log(msg.raw, scope=LogScope.RAW, out=False)
-        super().handle_msg(msg)
+        try:
+            super().handle_msg(msg)
+        except ImplementationFail as e:
+            self._log(str(e), scope=LogScope.DEBUG, alert=True)
 
     def _log(self, msg: str, scope: Optional[LogScope] = None, **kwargs
              ) -> None:
index ec08fe5c5326d07124b14608903f7926f97e8c57..583407ba6a4ea818135e376a1f2a96e031985c14 100644 (file)
--- a/test.txt
+++ b/test.txt
 
 # test lack of implementation
 0:2 < foo bar baz
-1,2 !$ PLEASE IMPLEMENT HANDLER FOR: foo bar baz
+1,2 !$ No handler implemented for: foo bar baz
 
 # test recoverable 432
 > /nick @foo