irkerd: Record errors (for example bad-password messages)
authorW. Trevor King <wking@tremily.us>
Fri, 30 May 2014 00:11:41 +0000 (17:11 -0700)
committerW. Trevor King <wking@tremily.us>
Fri, 30 May 2014 23:24:17 +0000 (16:24 -0700)
We can use these to distinguish between lost connections because of
flaky connections (where trying again is useful) and lost connections
because of bad passwords (where we should just give up).

irkerd

diff --git a/irkerd b/irkerd
index 9cbb3470efb8d37c9b5bad4a4ceeac9b1cc8588d..070e0e9e25048a03db422de8fe112e25f2915ad9 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -546,6 +546,7 @@ class IRCProtocol(StateStringOwner, Lock, LineProtocol):
                  handshake_ttl=None, transmit_ttl=None, receive_ttl=None,
                  anti_flood_delay=None, **kwargs):
         super(IRCProtocol, self).__init__(state='unseen', **kwargs)
+        self.errors = []
         self._password = password
         self._nick_template = nick_template
         if nick_needs_number is None:
@@ -674,6 +675,8 @@ class IRCProtocol(StateStringOwner, Lock, LineProtocol):
             self._handle_part(channel=target)
         elif command == 'featurelist':
             self._handle_features(arguments=arguments)
+        elif command == 'error':
+            self._handle_error(message=target)
         elif command == 'disconnect':
             self._handle_disconnect()
         elif command == 'kick':
@@ -766,6 +769,11 @@ class IRCProtocol(StateStringOwner, Lock, LineProtocol):
                     LOG.error('{}: ill-formed CHANLIMIT property'.format(
                         self))
 
+    def _handle_error(self, message):
+        "Server sent us an error message."
+        LOG.info('{}: server error: {}'.format(self, message))
+        self.errors.append(message)
+
     def _handle_disconnect(self):
         "Server disconnected us for flooding or some other reason."
         LOG.info('{}: server disconnected'.format(self))