Rev 4670: Don't return -1 directly, instead raise an exception. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-btree-better-errors

John Arbash Meinel john at arbash-meinel.com
Thu Oct 1 21:50:43 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-btree-better-errors

------------------------------------------------------------
revno: 4670
revision-id: john at arbash-meinel.com-20091001205036-l47i24kihxj7hmem
parent: pqm at pqm.ubuntu.com-20090925210528-kxssbjs9to8ob22a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.1-btree-better-errors
timestamp: Thu 2009-10-01 15:50:36 -0500
message:
  Don't return -1 directly, instead raise an exception.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2009-06-22 12:52:39 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2009-10-01 20:50:36 +0000
@@ -186,14 +186,13 @@
             # And the next string is right after it
             self._cur_str = last + 1
             # The last character is right before the '\n'
-            last = last
 
         if last == self._start:
             # parsed it all.
             return 0
         if last < self._start:
             # Unexpected error condition - fail
-            return -1
+            raise AssertionError("last < self._start")
         if 0 == self._header_found:
             # The first line in a leaf node is the header "type=leaf\n"
             if strncmp("type=leaf", self._start, last - self._start) == 0:
@@ -202,14 +201,13 @@
             else:
                 raise AssertionError('Node did not start with "type=leaf": %r'
                     % (safe_string_from_size(self._start, last - self._start)))
-                return -1
 
         key = self.extract_key(last)
         # find the value area
         temp_ptr = <char*>_my_memrchr(self._start, c'\0', last - self._start)
         if temp_ptr == NULL:
             # Invalid line
-            return -1
+            raise AssertionError("Failed to find the value area")
         else:
             # capture the value string
             value = safe_string_from_size(temp_ptr + 1, last - temp_ptr - 1)
@@ -223,15 +221,15 @@
                 # extract a reference list
                 loop_counter = loop_counter + 1
                 if last < self._start:
-                    return -1
+                    raise AssertionError("last < self._start")
                 # find the next reference list end point:
                 temp_ptr = <char*>memchr(self._start, c'\t', last - self._start)
                 if temp_ptr == NULL:
                     # Only valid for the last list
                     if loop_counter != self.ref_list_length:
                         # Invalid line
-                        return -1
-                        raise AssertionError("invalid key")
+                        raise AssertionError(
+                            "invalid key, loop_counter != self.ref_list_length")
                     else:
                         # scan to the end of the ref list area
                         ref_ptr = last
@@ -257,7 +255,7 @@
         else:
             if last != self._start:
                 # unexpected reference data present
-                return -1
+                raise AssertionError("unexpected reference data present")
             node_value = (value, ())
         PyList_Append(self.keys, (key, node_value))
         return 0



More information about the bazaar-commits mailing list