[PATCH 1/5] Add OfflineImapError class

Sebastian Spaeth Sebastian at SSpaeth.de
Wed May 4 15:45:24 BST 2011


This Exception can be thrown whenever a sync error occurs. It is used
for outputting sensible error messages to the user and it denotes a
"severity", it can tell offlineimap if we need to abort a message, a
folder, a repo sync, or whether we should indeed abort immediately.

The exception is not yet used in the code.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/__init__.py |    1 +
 offlineimap/error.py    |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 offlineimap/error.py

diff --git a/offlineimap/__init__.py b/offlineimap/__init__.py
index 273faef..0a55a97 100644
--- a/offlineimap/__init__.py
+++ b/offlineimap/__init__.py
@@ -18,6 +18,7 @@ to distribute it under the conditions laid out in COPYING."""
 __homepage__ = "http://github.com/nicolas33/offlineimap"
 __license__  = "Licensed under the GNU GPL v2+ (v2 or any later version)."
 
+from offlineimap.error import OfflineImapError
 # put this last, so we don't run into circular dependencies using 
 # e.g. offlineimap.__version__.
 from offlineimap.init import OfflineImap
diff --git a/offlineimap/error.py b/offlineimap/error.py
new file mode 100644
index 0000000..d4d16be
--- /dev/null
+++ b/offlineimap/error.py
@@ -0,0 +1,33 @@
+class OfflineImapError(Exception):
+    """An Error during offlineimap synchronization"""
+
+    class ERROR:
+        """Severity levels"""
+        MESSAGE  = 0
+        FOLDER   = 10
+        REPO     = 20
+        CRITICAL = 30
+
+    def __init__(self, reason, severity, errcode=None):
+        """
+        :param reason: Human readable string suitable for logging
+
+        :param severity: denoting which operations should be
+               aborted. E.g. a ERROR.MESSAGE can occur on a faulty
+               message, but a ERROR.REPO occurs when the server is
+               offline.
+
+         :param errcode: optional number denoting a predefined error
+               situation (which let's us exit with a predefined exit
+               value). So far, no errcodes have been defined yet.
+
+        :type severity: OfflineImapError.ERROR value"""
+        self.errcode  = errcode
+        self.severity = severity
+
+        # 'reason' is stored in the Exception().args tuple.
+        super(OfflineImapError, self).__init__(reason)
+
+    @property
+    def reason(self):
+        return self.args[0]
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list