From b6275130e1f0f3e94b35443674665d406b2349af Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 18 Jul 2015 20:10:33 -0700 Subject: [PATCH] Irc: catch AttributeError when self.socket doesn't exist (failed to establish initial connection) --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 568764b..7b8f8a5 100755 --- a/main.py +++ b/main.py @@ -160,8 +160,12 @@ class Irc(): # treated as a separate command, which is particularly nasty. data = data.replace('\n', ' ') data = data.encode("utf-8") + b"\n" - log.debug("(%s) -> %s", self.name, data.decode("utf-8").strip("\n")) - self.socket.send(data) + stripped_data = data.decode("utf-8").strip("\n") + log.debug("(%s) -> %s", self.name, stripped_data) + try: + self.socket.send(data) + except AttributeError: + log.debug("(%s) Dropping message %r; network isn't connected!", self.name, stripped_data) def schedulePing(self): self.proto.pingServer(self)