[PATCH] improve message "error 111" if connection failed
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Wed May 25 19:38:37 BST 2011
On Wed, May 25, 2011 at 01:05:35PM +0200, Sebastian Spaeth wrote:
> HOLD ON, PLEASE DON'T MERGE. I would argue this is the wrong place to
> raise that warning. Right now, you only treat the SSL case for example.
Don't cry, I let contributors time to review my patches.
> ALL the connection opening passes through imapserver.acquireconnection()
> and it is here that we already raise DNS related errors:
>
> if type(e) == gaierror:
> #DNS related errors. Abort Repo sync
> severity = OfflineImapError.ERROR.REPO
> #TODO: special error msg for e.errno == 2 "Name or service not
> known"?
> reason = "Could not resolve name '%s' for repository "\
> "'%s'. Make sure you have configured the ser"\
> "ver name correctly and that you are online."\
> % (self.hostname, self.reposname)
> raise OfflineImapError(reason, severity)
>
> And it is here, that we should also catch the "connection refused"
> error. This way we catch SSL nonSSL and all possible other connection
> creation errors.
Right. I'm not totally satisfied with following patch (based on str(e)) but I
don't have much time for this issue. So, here I am. If any taker, this is the
one I'll merge.
-- >8 --
Subject: [PATCH] improve message "error 111" if connection failed
Raise OfflineImapError with severity REPO explaining that the connection failed.
Before, no valuable information was given to the user.
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
offlineimap/imaplibutil.py | 8 ++++----
offlineimap/imapserver.py | 7 +++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index 6c6142c..f501af6 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -172,8 +172,8 @@ class WrappedIMAP4_SSL(UsefulIMAPMixIn, IMAP4_SSL):
else:
self.sock.close()
if last_error != 0:
- # FIXME
- raise socket.error(last_error)
+ raise Exception("can't open socket; error: %s"\
+ % socket.error(last_error))
# Allow sending of keep-alive message seems to prevent some servers
# from closing SSL on us leading to deadlocks
@@ -276,8 +276,8 @@ class WrappedIMAP4(UsefulIMAPMixIn, IMAP4):
else:
self.sock.close()
if last_error != 0:
- # FIXME
- raise socket.error(last_error)
+ raise Exception("can't open socket; error: %s"\
+ % socket.error(last_error))
self.file = self.sock.makefile('rb')
# imaplib2 uses this to poll()
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 147e84b..37fc553 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -289,6 +289,13 @@ class IMAPServer:
"ver name correctly and that you are online."\
% (self.hostname, self.reposname)
raise OfflineImapError(reason, severity)
+ # Could not acquire connection to the remote;
+ # socket.error(last_error) raised
+ if str(e)[:24] == "can't open socket; error":
+ raise OfflineImapError("Could not connect to remote server '%s' "\
+ "for repository '%s'. Remote does not answer."
+ % (self.hostname, self.reposname),
+ OfflineImapError.ERROR.REPO)
else:
# re-raise all other errors
raise
--
1.7.5.1.354.g761178
More information about the OfflineIMAP-project
mailing list