Properly re-raise exception to save original tracebacks
We usually mutate some exceptions to OfflineImapError() and it is a whole lot better if such exception will show up with the original traceback, so all valid occurrences of such mutations were transformed to the 3-tuple form of "raise". Had also added coding guidelines document where this re-raise strategy is documented. Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import re
|
||||
from sys import exc_info
|
||||
|
||||
from offlineimap import imaputil, OfflineImapError
|
||||
from offlineimap import imaplibutil
|
||||
@ -144,7 +145,8 @@ class GmailFolder(IMAPFolder):
|
||||
raise OfflineImapError("FETCHING UIDs in folder [%s]%s failed. " % \
|
||||
(self.getrepository(), self) + \
|
||||
"Server responded '[%s] %s'" % \
|
||||
(res_type, response), OfflineImapError.ERROR.FOLDER)
|
||||
(res_type, response), OfflineImapError.ERROR.FOLDER), \
|
||||
None, exc_info()[2]
|
||||
finally:
|
||||
self.imapserver.releaseconnection(imapobj)
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
import os
|
||||
from sys import exc_info
|
||||
from .Maildir import MaildirFolder
|
||||
from offlineimap import OfflineImapError
|
||||
import offlineimap.accounts
|
||||
@ -170,7 +171,8 @@ class GmailMaildirFolder(MaildirFolder):
|
||||
os.rename(tmppath, filepath)
|
||||
except OSError as e:
|
||||
raise OfflineImapError("Can't rename file '%s' to '%s': %s" % \
|
||||
(tmppath, filepath, e[1]), OfflineImapError.ERROR.FOLDER)
|
||||
(tmppath, filepath, e[1]), OfflineImapError.ERROR.FOLDER), \
|
||||
None, exc_info()[2]
|
||||
|
||||
if rtime != None:
|
||||
os.utime(filepath, (rtime, rtime))
|
||||
|
@ -594,7 +594,9 @@ class IMAPFolder(BaseFolder):
|
||||
"repository '%s' failed (abort). Server responded: %s\n"
|
||||
"Message content was: %s"%
|
||||
(msg_id, self, self.getrepository(), str(e), dbg_output),
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
OfflineImapError.ERROR.MESSAGE), \
|
||||
None, exc_info()[2]
|
||||
# XXX: is this still needed?
|
||||
self.ui.error(e, exc_info()[2])
|
||||
except imapobj.error as e: # APPEND failed
|
||||
# If the server responds with 'BAD', append()
|
||||
@ -604,8 +606,8 @@ class IMAPFolder(BaseFolder):
|
||||
imapobj = None
|
||||
raise OfflineImapError("Saving msg (%s) folder '%s', repo '%s'"
|
||||
"failed (error). Server responded: %s\nMessage content was: "
|
||||
"%s"% (msg_id, self, self.getrepository(), str(e), dbg_output),
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
"%s" % (msg_id, self, self.getrepository(), str(e), dbg_output),
|
||||
OfflineImapError.ERROR.MESSAGE), None, exc_info()[2]
|
||||
# Checkpoint. Let it write out stuff, etc. Eg searches for
|
||||
# just uploaded messages won't work if we don't do this.
|
||||
(typ,dat) = imapobj.check()
|
||||
@ -676,6 +678,7 @@ class IMAPFolder(BaseFolder):
|
||||
imapobj = self.imapserver.acquireconnection()
|
||||
self.ui.error(e, exc_info()[2])
|
||||
fails_left -= 1
|
||||
# self.ui.error() will show the original traceback
|
||||
if not fails_left:
|
||||
raise e
|
||||
if data == [None] or res_type != 'OK':
|
||||
|
@ -15,6 +15,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from sys import exc_info
|
||||
import os
|
||||
import threading
|
||||
|
||||
@ -79,7 +80,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
errstr = "Corrupt line '%s' in cache file '%s'" % \
|
||||
(line, self.filename)
|
||||
self.ui.warn(errstr)
|
||||
raise ValueError(errstr)
|
||||
raise ValueError(errstr), None, exc_info()[2]
|
||||
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
||||
self.messagelist[uid]['flags'] = flags
|
||||
|
||||
@ -103,7 +104,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
errstr = "Corrupt line '%s' in cache file '%s'" % \
|
||||
(line, self.filename)
|
||||
self.ui.warn(errstr)
|
||||
raise ValueError(errstr)
|
||||
raise ValueError(errstr), None, exc_info()[2]
|
||||
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
||||
self.messagelist[uid]['flags'] = flags
|
||||
self.messagelist[uid]['mtime'] = mtime
|
||||
|
@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
import os
|
||||
import re
|
||||
from sys import exc_info
|
||||
from threading import Lock
|
||||
from .Base import BaseFolder
|
||||
try:
|
||||
@ -66,7 +67,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
||||
except NameError:
|
||||
# sqlite import had failed
|
||||
raise UserWarning('SQLite backend chosen, but no sqlite python '
|
||||
'bindings available. Please install.')
|
||||
'bindings available. Please install.'), None, exc_info()[2]
|
||||
|
||||
#Make sure sqlite is in multithreading SERIALIZE mode
|
||||
assert sqlite.threadsafety == 1, 'Your sqlite is not multithreading safe.'
|
||||
|
@ -19,6 +19,7 @@ import socket
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
from sys import exc_info
|
||||
from .Base import BaseFolder
|
||||
from threading import Lock
|
||||
try:
|
||||
@ -282,7 +283,7 @@ class MaildirFolder(BaseFolder):
|
||||
continue
|
||||
severity = OfflineImapError.ERROR.MESSAGE
|
||||
raise OfflineImapError("Unique filename %s already exists." % \
|
||||
filename, severity)
|
||||
filename, severity), None, exc_info()[2]
|
||||
else:
|
||||
raise
|
||||
|
||||
@ -372,7 +373,8 @@ class MaildirFolder(BaseFolder):
|
||||
except OSError as e:
|
||||
raise OfflineImapError("Can't rename file '%s' to '%s': %s" % (
|
||||
oldfilename, newfilename, e[1]),
|
||||
OfflineImapError.ERROR.FOLDER)
|
||||
OfflineImapError.ERROR.FOLDER), \
|
||||
None, exc_info()[2]
|
||||
|
||||
self.messagelist[uid]['flags'] = flags
|
||||
self.messagelist[uid]['filename'] = newfilename
|
||||
|
@ -14,6 +14,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from sys import exc_info
|
||||
from threading import Lock
|
||||
from offlineimap import OfflineImapError
|
||||
from .IMAP import IMAPFolder
|
||||
@ -60,7 +62,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
line = line.strip()
|
||||
except ValueError:
|
||||
raise Exception("Corrupt line '%s' in UID mapping file '%s'"%
|
||||
(line, mapfilename))
|
||||
(line, mapfilename)), None, exc_info()[2]
|
||||
(str1, str2) = line.split(':')
|
||||
loc = long(str1)
|
||||
rem = long(str2)
|
||||
@ -89,7 +91,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
raise OfflineImapError("Could not find UID for msg '{0}' (f:'{1}'."
|
||||
" This is usually a bad thing and should be reported on the ma"
|
||||
"iling list.".format(e.args[0], self),
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
OfflineImapError.ERROR.MESSAGE), None, exc_info()[2]
|
||||
|
||||
# Interface from BaseFolder
|
||||
def cachemessagelist(self):
|
||||
|
Reference in New Issue
Block a user