[PATCH] Output more detailed error on corrupt LocalStatus

Sebastian Spaeth Sebastian at SSpaeth.de
Tue May 3 18:04:56 BST 2011


When our LocalStatus cache is corrupt, ie e.g. it contains lines not in
the form number:number, we would previously just raise a ValueError
stating things like "too many values". In case we encounter clearly
corrupt LocalStatus cache entries, clearly raise an exception stating
the filename and the line, so that people can attempt to repair it.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
Unfortunately, we currently just continue with the next folder when we
currently encounter this. I would prefer we abort offlineimap completely
on a corrupt cache file. But this will have to wait until we get proper
error messages (which are high up on my list)

This patch is based on master and should go in mainline, I guess.
 offlineimap/folder/LocalStatus.py |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index 623829a..4bbcb26 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -78,8 +78,14 @@ class LocalStatusFolder(BaseFolder):
         assert(line == magicline)
         for line in file.xreadlines():
             line = line.strip()
-            uid, flags = line.split(':')
-            uid = long(uid)
+            try:
+                uid, flags = line.split(':')
+                uid = long(uid)
+            except ValueError as e:
+                errstr = "Corrupt line '%s' in cache file '%s'" \
+                         % (line, self.filename)
+                self.ui.warn(errstr)
+                raise ValueError(errstr)
             flags = [x for x in flags]
             self.messagelist[uid] = {'uid': uid, 'flags': flags}
         file.close()
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list