changeset 633:37b2adc64fb3

editor: convert two assertions in apply_textdelta() into raising an IOError I noticed these in the traceback filed as issue2261 in the Mercurial bug tracker. We should always fail in cases where the Subversion server gives us invalid data, so using assertions is wrong.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 08 Jul 2010 21:46:54 +0200
parents eea224fa1156
children a400f3bf5611
files hgsubversion/editor.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/editor.py
+++ b/hgsubversion/editor.py
@@ -1,3 +1,4 @@
+import errno
 import cStringIO
 import sys
 
@@ -330,10 +331,18 @@ class HgEditor(svnwrap.Editor):
         base = ''
         if not self.meta.is_path_valid(self.current.file):
             return lambda x: None
-        assert self.current.file not in self.current.deleted, (
-            'Cannot apply_textdelta to a deleted file: %s' % self.current.file)
-        assert (self.current.file in self.current.files
-                or self.current.file in self.current.missing), '%s not found' % self.current.file
+
+        if self.current.file in self.current.deleted:
+            msg = ('cannot apply textdelta to %s: file is deleted'
+                   % self.current.file)
+            raise IOError(errno.ENOENT, msg)
+
+        if (self.current.file not in self.current.files and
+            self.current.file not in self.current.missing):
+            msg = ('cannot apply textdelta to %s: file not found'
+                   % self.current.file)
+            raise IOError(errno.ENOENT, msg)
+
         if self.current.file in self.current.missing:
             return lambda x: None
         base = self.current.files[self.current.file]