Patch series for proper error messages

Sebastian Spaeth Sebastian at
Wed May 4 15:44:33 BST 2011

OK, following a patch series that lays the foundation for proper error
messages rather than always (often obscure) traceback "crashes".
We can throw OfflineImapErrors or severity MESSAGE (skip this message
and continue), FOLDER (skip this folder and continue), REPO (skip this
account and continue), or CRITICAL (abort the application).

A first sample error in this series is thrown on DNS errors (or when offline),
Test it  by filling in a bogus host name or unplugging your computer.

I made it so that when we are in an autorefresh loop, that we abort the
account sync after 3 subsequent failure runs (of REPO severity). A
successfull sync resets the counter to 3. This behavior can be debated
and improved, but it lets intermittent network errors pass while still
bombing out on permanent errors.

The patches (on top of master):
effaf6c Add OfflineImapError class (adds the custom Exception, which is
        still unused)
6fa60a8 Throw OfflineImapError on DNS error (implements first Exception
        on DNS related errors)
d3ee1dc Remove duplicated code paths (cleanup patch that allowed me to
        only catch the Exception in one rather than 2 places)
f57b4bc Handle OfflineImapError of severity REPO and CRIT (abort account
        synchronization when we get an offlineimapError of this severity)
b7acd47 If we loop, exit the account synchronization after 3 failed attempts

Compare the old and the new output:
 ***** Processing account
 Copying folder structure from IMAP to Maildir
 Establishing connection to
 WARNING: Error occured attempting to sync account Traceback (most recent call last):
  File "/home/spaetz/src/offlineimap/offlineimap/", line 191, in syncrunner
  File "/home/spaetz/src/offlineimap/offlineimap/", line 246, in sync
    remoterepos.syncfoldersto(localrepos, [statusrepos])
  File "/home/spaetz/src/offlineimap/offlineimap/repository/", line 121, in syncfoldersto
    srcfolders = src.getfolders()
  File "/home/spaetz/src/offlineimap/offlineimap/repository/", line 242, in getfolders
    imapobj = self.imapserver.acquireconnection()
  File "/home/spaetz/src/offlineimap/offlineimap/", line 207, in acquireconnection
    cacertfile = self.sslcacertfile)
  File "/home/spaetz/src/offlineimap/offlineimap/", line 141, in __init__
    IMAP4_SSL.__init__(self, *args, **kwargs)
  File "/home/spaetz/src/offlineimap/offlineimap/", line 1871, in __init__
    IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout)
  File "/home/spaetz/src/offlineimap/offlineimap/", line 309, in __init__, port)
  File "/home/spaetz/src/offlineimap/offlineimap/", line 157, in open
gaierror: [Errno -2] Name or service not known
 ***** Finished processing account


***** Processing account
Copying folder structure from IMAP to Maildir
Establishing connection to
WARNING: Could not resolve name '' for repository 'Remote'. Make sure you have configured the server name correctly and that you are online.
***** Finished processing account
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <>

More information about the OfflineIMAP-project mailing list