3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-11 12:42:34 +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.
This commit is contained in:
James Lu 2017-03-26 14:13:26 -07:00
parent ce0c84266e
commit 397df48efd

View File

@ -28,7 +28,7 @@ from .log import *
### Exceptions
class ProtocolError(Exception):
class ProtocolError(RuntimeError):
pass
### Internal classes (users, servers, channels)
@ -322,7 +322,11 @@ class Irc(utils.DeprecatedAttributesObject):
'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',