From 3cefaa86175aba79410fe296f25c40923b8af572 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Fri, 19 Mar 2021 21:49:03 +0000 Subject: [PATCH] Don't reconnect on MessageTooLong exceptions If a user pushes a commit with an overly-long subject (most often forgetting to separate it from the rest of the commit message with a blank line), the resulting IRC message will be longer than the protocol allows. In these cases, irc.client.MessageTooLong is raised. This is an unfortunately all-too-common occurrence, so catch it specifically in order to not enter the reconnect phase needlessly. Log the failure to send, so that it can still be found if someone is trying to identify the reason a change was not announced. Change-Id: I3cfaa3ea3b3f8f2de20bfe425c345385eb7cbba6 --- gerritbot/bot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gerritbot/bot.py b/gerritbot/bot.py index 6dcdcf0..4ab7712 100755 --- a/gerritbot/bot.py +++ b/gerritbot/bot.py @@ -21,6 +21,7 @@ import daemon from ib3.auth import SASL from ib3.connection import SSL import irc.bot +import irc.client import json import logging.config import os @@ -130,6 +131,13 @@ class GerritBot(SASL, SSL, irc.bot.SingleServerIRCBot): try: self.connection.privmsg(channel_name, msg) time.sleep(0.5) + except irc.client.MessageTooLong: + # If the server chokes because we tried to send something >512 + # bytes long, just ignore it, sometimes users forget to separate + # the commit subject from the body with a blank line (a future + # alternative could be to truncate to some safe length and retry) + self.log.exception('Message was too long so not sent:') + pass except Exception: # If an exception was raised on sending, suspect that there may be # trouble with the connection and try to reconnect, explicitly