[PATCH 3/4] accounts.py: Use ui.error when raising exceptions

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Jun 14 09:23:41 BST 2011


Rather than using ui.warn, use ui.error() which outputs Exceptions to
the error log, saving them to a stack, so we get notified again at the
end of the sync run.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/accounts.py |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index a989441..f0a18b6 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -22,6 +22,7 @@ from offlineimap.threadutil import InstanceLimitedThread
 from subprocess import Popen, PIPE
 from threading import Event
 import os
+import sys
 import traceback
 
 def getaccountlist(customconfig):
@@ -178,16 +179,16 @@ class SyncableAccount(Account):
                 except (KeyboardInterrupt, SystemExit):
                     raise
                 except OfflineImapError, e:                    
-                    self.ui.warn(e.reason)
                     # Stop looping and bubble up Exception if needed.
                     if e.severity >= OfflineImapError.ERROR.REPO:
                         if looping:
                             looping -= 1
                         if e.severity >= OfflineImapError.ERROR.CRITICAL:
                             raise
-                except:
-                    self.ui.warn("Error occured attempting to sync account "\
-                                 "'%s':\n%s"% (self, traceback.format_exc()))
+                    self.ui.error(e, sys.exc_traceback)
+                except Exception, e:
+                    self.ui.error(e, msg = "While attempting to sync "
+                        "account %s:\n  %s"% (self, traceback.format_exc()))
                 else:
                     # after success sync, reset the looping counter to 3
                     if self.refreshperiod:
@@ -276,8 +277,10 @@ class SyncableAccount(Account):
             r = p.communicate()
             self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % r)
             self.ui.callhook("Hook return code: %d" % p.returncode)
-        except:
-            self.ui.warn("Exception occured while calling hook")
+        except (KeyboardInterrupt, SystemExit):
+            raise
+        except Exception, e:
+            self.ui.error(e, sys.exc_traceback, msg = "Calling hook")
 
 
 def syncfolder(accountname, remoterepos, remotefolder, localrepos,
@@ -366,9 +369,9 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
         if e.severity > OfflineImapError.ERROR.FOLDER:
             raise
         else:
-            ui.warn("Aborting folder sync '%s' [acc: '%s']\nReason was: %s" %\
-                        (localfolder.name, accountname, e.reason))
-    except:
-        ui.warn("ERROR in syncfolder for %s folder %s: %s" % \
+            ui.error(e, sys.exc_traceback, msg = "Aborting folder sync '%s' "
+                     "[acc: '%s']" % (localfolder, accountname))
+    except Exception, e:
+        ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \
                 (accountname,remotefolder.getvisiblename(),
                  traceback.format_exc()))
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list