don't fail to report error when exception args are not as expected

Also, quit the "elif" logic because each case is raising an exception.

Fixes #97
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2021-10-30 23:55:00 +02:00
parent e64c254072
commit f418754087

View File

@ -648,7 +648,7 @@ class IMAPServer:
(self.hostname, self.repos) (self.hostname, self.repos)
raise OfflineImapError(reason, severity, exc_info()[2]) raise OfflineImapError(reason, severity, exc_info()[2])
elif isinstance(e, SSLError) and e.errno == errno.EPERM: if isinstance(e, SSLError) and e.errno == errno.EPERM:
# SSL unknown protocol error # SSL unknown protocol error
# happens e.g. when connecting via SSL to a non-SSL service # happens e.g. when connecting via SSL to a non-SSL service
if self.port != 993: if self.port != 993:
@ -662,7 +662,7 @@ class IMAPServer:
% (self.hostname, self.repos, e) % (self.hostname, self.repos, e)
raise OfflineImapError(reason, severity, exc_info()[2]) raise OfflineImapError(reason, severity, exc_info()[2])
elif isinstance(e, socket.error) and e.args and e.args[0] == errno.ECONNREFUSED: if isinstance(e, socket.error) and e.args and e.args[0] == errno.ECONNREFUSED:
# "Connection refused", can be a non-existing port, or an unauthorized # "Connection refused", can be a non-existing port, or an unauthorized
# webproxy (open WLAN?) # webproxy (open WLAN?)
reason = "Connection to host '%s:%d' for repository '%s' was " \ reason = "Connection to host '%s:%d' for repository '%s' was " \
@ -679,16 +679,20 @@ class IMAPServer:
"for repository '%s'. Remote does not answer." % (self.hostname, self.repos), "for repository '%s'. Remote does not answer." % (self.hostname, self.repos),
OfflineImapError.ERROR.REPO, OfflineImapError.ERROR.REPO,
exc_info()[2]) exc_info()[2])
elif e.args and \ if e.args:
e.args[0][:35] == 'IMAP4 protocol error: socket error:': try:
raise OfflineImapError( if e.args[0][:35] == 'IMAP4 protocol error: socket error:':
"Could not connect to remote server '{}' " raise OfflineImapError(
"for repository '{}'. Connection Refused.".format( "Could not connect to remote server '{}' "
self.hostname, self.repos), "for repository '{}'. Connection Refused.".format(
OfflineImapError.ERROR.CRITICAL) self.hostname, self.repos),
else: OfflineImapError.ERROR.CRITICAL)
# re-raise all other errors except:
raise pass
e.args[0][:35]
# re-raise all other errors
raise
def connectionwait(self): def connectionwait(self):
"""Waits until there is a connection available. """Waits until there is a connection available.