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
This commit is contained in:
Jeremy Stanley 2021-03-19 21:49:03 +00:00
parent 03c21d8369
commit 3cefaa8617
1 changed files with 8 additions and 0 deletions

View File

@ -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