[PATCH] improve message "error 111" if connection failed

Sebastian Spaeth Sebastian at SSpaeth.de
Wed May 25 12:05:35 BST 2011

On Tue, 24 May 2011 23:58:43 +0200, <nicolas.s-dev at laposte.net> wrote:
> Raise OfflineImapError with severity REPO explaining that the connection failed.
> Before, no valuable information was given to the user.

> --- a/offlineimap/imaplibutil.py
> +++ b/offlineimap/imaplibutil.py
> @@ -172,8 +172,9 @@ class WrappedIMAP4_SSL(UsefulIMAPMixIn, IMAP4_SSL):
>              else:
>                  self.sock.close()
>          if last_error != 0:
> -            # FIXME
> -            raise socket.error(last_error)
> +            raise OfflineImapError(
> +                "connection to a remote failed with error %s" % socket.error(last_error),
> +                OfflineImapError.ERROR.REPO)

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.

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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20110525/861878ad/attachment-0001.sig>

More information about the OfflineIMAP-project mailing list