D4654: error: introduce StorageError

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Sep 18 20:06:19 EDT 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Errors in revlogs are often represented by RevlogError. It's fine
  for revlogs to raise a revlog-specific exception. But in the context
  of multiple storage backends, it doesn't make sense to be throwing or
  catching an exception with "revlog" in its name when revlogs may not
  even be in play.
  
  This commit introduces a new generic StorageError type for representing
  errors in the storage layer.
  
  RevlogError is an instance of this type.
  
  Interface documentation and tests referencing RevlogError has been
  updated to specify StorageError should be used.
  
  .. api::
  
    ``error.StorageError`` has been introduced to represent errors in
    storage. It should be used in place of ``error.RevlogError`` unless
    the error is known to come from a revlog.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4654

AFFECTED FILES
  mercurial/error.py
  mercurial/repository.py
  mercurial/testing/storage.py

CHANGE DETAILS

diff --git a/mercurial/testing/storage.py b/mercurial/testing/storage.py
--- a/mercurial/testing/storage.py
+++ b/mercurial/testing/storage.py
@@ -422,7 +422,7 @@
             with self.assertRaises(IndexError):
                 f.size(i)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(b'', nullid)
 
         with self.assertRaises(error.LookupError):
@@ -527,13 +527,13 @@
         f.checkhash(fulltext, node)
         f.checkhash(fulltext, node, nullid, nullid)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext + b'extra', node)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext, node, b'\x01' * 20, nullid)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext, node, nullid, b'\x01' * 20)
 
         self.assertEqual(f.revision(node), fulltext)
@@ -603,13 +603,13 @@
         f.checkhash(fulltext1, node1, node0, nullid)
         f.checkhash(fulltext2, node2, node1, nullid)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext1, b'\x01' * 20)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext1 + b'extra', node1, node0, nullid)
 
-        with self.assertRaises(error.RevlogError):
+        with self.assertRaises(error.StorageError):
             f.checkhash(fulltext1, node1, node0, node0)
 
         self.assertEqual(f.revision(node0), fulltext0)
@@ -852,7 +852,7 @@
         f = self._makefilefn()
         with self._maketransactionfn() as tr:
             # Adding a revision with bad node value fails.
-            with self.assertRaises(error.RevlogError):
+            with self.assertRaises(error.StorageError):
                 f.addrevision(b'foo', tr, 0, nullid, nullid, node=b'\x01' * 20)
 
     def testaddrevisionunknownflag(self):
@@ -863,7 +863,7 @@
                     flags = 1 << i
                     break
 
-            with self.assertRaises(error.RevlogError):
+            with self.assertRaises(error.StorageError):
                 f.addrevision(b'foo', tr, 0, nullid, nullid, flags=flags)
 
     def testaddgroupsimple(self):
@@ -891,7 +891,7 @@
         ]
 
         with self._maketransactionfn() as tr:
-            with self.assertRaises(error.RevlogError):
+            with self.assertRaises(error.StorageError):
                 f.addgroup(deltas, linkmapper, tr, addrevisioncb=cb)
 
             node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -571,7 +571,7 @@
     def checkhash(fulltext, node, p1=None, p2=None, rev=None):
         """Validate the stored hash of a given fulltext and node.
 
-        Raises ``error.RevlogError`` is hash validation fails.
+        Raises ``error.StorageError`` is hash validation fails.
         """
 
     def revision(node, raw=False):
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -34,7 +34,14 @@
         self.hint = kw.pop(r'hint', None)
         super(Hint, self).__init__(*args, **kw)
 
-class RevlogError(Hint, Exception):
+class StorageError(Hint, Exception):
+    """Raised when an error occurs in a storage layer.
+
+    Usually subclassed by a storage-specific exception.
+    """
+    __bytes__ = _tobytes
+
+class RevlogError(StorageError):
     __bytes__ = _tobytes
 
 class FilteredIndexError(IndexError):



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list