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:
Eygene Ryabinkin
2015-01-11 23:44:24 +03:00
parent 8c6abc413e
commit e7fabf9e57
15 changed files with 150 additions and 26 deletions

View File

@ -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