accounts.py: Use ui.error when raising exceptions

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@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-08-11 12:22:35 +02:00 committed by Nicolas Sebrecht
parent f937a86571
commit b47bc44783
3 changed files with 95 additions and 80 deletions

View File

@ -13,6 +13,10 @@ others.
New Features
------------
* When a message upload/download fails, we do not abort the whole folder
synchronization, but only skip that message, informing the user at the
end of the sync run.
Changes
-------

View File

@ -22,6 +22,7 @@ from offlineimap.threadutil import InstanceLimitedThread
from subprocess import Popen, PIPE
from threading import Event
import os
from sys import exc_info
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, exc_info()[2])
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, exc_info()[2], 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, exc_info()[2], 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()))

View File

@ -19,6 +19,7 @@ from offlineimap import threadutil
from offlineimap.ui import getglobalui
import os.path
import re
from sys import exc_info
import traceback
class BaseFolder(object):
@ -229,7 +230,6 @@ class BaseFolder(object):
# synced to the status cache. This is only a problem with
# self.getmessage(). So, don't call self.getmessage unless
# really needed.
try:
if register: # output that we start a new thread
self.ui.registerthread(self.getaccountname())
@ -246,7 +246,6 @@ class BaseFolder(object):
# If any of the destinations actually stores the message body,
# load it up.
if dstfolder.storesmessages():
message = self.getmessage(uid)
#Succeeded? -> IMAP actually assigned a UID. If newid
#remained negative, no server was willing to assign us an
@ -264,6 +263,7 @@ class BaseFolder(object):
uid = newuid
# Save uploaded status in the statusfolder
statusfolder.savemessage(uid, message, flags, rtime)
elif newuid == 0:
# Message was stored to dstfolder, but we can't find it's UID
# This means we can't link current message to the one created
@ -273,18 +273,12 @@ class BaseFolder(object):
# IMAP servers ...
self.deletemessage(uid)
else:
raise UserWarning("Trying to save msg (uid %d) on folder "
raise OfflineImapError("Trying to save msg (uid %d) on folder "
"%s returned invalid uid %d" % \
(uid,
dstfolder.getvisiblename(),
newuid))
except (KeyboardInterrupt):
raise
except:
self.ui.warn("ERROR attempting to copy message " + str(uid) \
+ " for account " + self.getaccountname() + ":" \
+ traceback.format_exc())
raise
newuid),
OfflineImapError.ERROR.MESSAGE)
def syncmessagesto_copy(self, dstfolder, statusfolder):
"""Pass1: Copy locally existing messages not on the other side
@ -303,6 +297,7 @@ class BaseFolder(object):
statusfolder.uidexists(uid),
self.getmessageuidlist())
for uid in copylist:
try:
if self.suggeststhreads():
self.waitforthread()
thread = threadutil.InstanceLimitedThread(\
@ -315,8 +310,17 @@ class BaseFolder(object):
thread.start()
threads.append(thread)
else:
self.copymessageto(uid, dstfolder, statusfolder, register = 0)
self.copymessageto(uid, dstfolder, statusfolder,
register = 0)
except OfflineImapError, e:
if e.severity > OfflineImapError.ERROR.Message:
raise # buble severe errors up
self.ui.error(e, exc_info()[2])
except Exception, e:
self.ui.error(e, "Copying message %s [acc: %s]:\n %s" %\
(uid, self.getaccountname(),
traceback.format_exc()))
raise #raise on unknown errors, so we can fix those
for thread in threads:
thread.join()
@ -421,8 +425,12 @@ class BaseFolder(object):
action(dstfolder, statusfolder)
except (KeyboardInterrupt):
raise
except:
self.ui.warn("ERROR attempting to sync flags " \
+ "for account " + self.getaccountname() \
+ ":" + traceback.format_exc())
except OfflineImap, e:
if e.severity > OfflineImapError.ERROR.FOLDER:
raise
self.ui.error(e, exc_info()[2])
except Exception, e:
self.ui.error(e, msg = "ERROR attempting to sync folder %s "
"[acc: %s]:\n %s" (self, self.getaccountname(),
traceback.format_exc()))
raise # raise unknown Exceptions so we can fix them