3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Irc: simplify runloop error catching, adding RuntimeError and SystemExit (closes #438)

socket.error is aliased to OSError since Python 3.3, and ConnectionError is actually a subclass of OSError.
So, it makes more sense to just catch the more generic type here.

Also, make ProtocolError derive from RuntimeError instead of Exception.

(cherry picked from commit 397df48efd)
This commit is contained in:
James Lu 2017-03-26 14:13:26 -07:00
parent 027c35b75a
commit d70ca9fa3b

View File

@ -27,7 +27,7 @@ from .log import *
### Exceptions
class ProtocolError(Exception):
class ProtocolError(RuntimeError):
pass
### Internal classes (users, servers, channels)
@ -312,7 +312,11 @@ class Irc():
'trying to set up this connection. Please check'
' your configuration file and try again.',
self.name)
except (socket.error, ProtocolError, ConnectionError) as e:
# Note: socket.error, ConnectionError, IOError, etc. are included in OSError since Python 3.3,
# so we don't need to explicitly catch them here.
# We also catch SystemExit here as a way to abort out connection threads properly, and stop the
# IRC connection from freezing instead.
except (OSError, RuntimeError, SystemExit) as e:
# self.run() or the protocol module it called raised an
# exception, meaning we've disconnected!
log.error('(%s) Disconnected from IRC: %s: %s',