changeset 39792:cb65d4b7e429

error: introduce StorageError 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. Differential Revision: https://phab.mercurial-scm.org/D4654
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 18 Sep 2018 16:45:13 -0700
parents 974592474dee
children b63dee7bd0d9
files mercurial/error.py mercurial/repository.py mercurial/testing/storage.py
diffstat 3 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/error.py	Tue Sep 18 16:28:17 2018 -0700
+++ b/mercurial/error.py	Tue Sep 18 16:45:13 2018 -0700
@@ -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):
--- a/mercurial/repository.py	Tue Sep 18 16:28:17 2018 -0700
+++ b/mercurial/repository.py	Tue Sep 18 16:45:13 2018 -0700
@@ -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):
--- a/mercurial/testing/storage.py	Tue Sep 18 16:28:17 2018 -0700
+++ b/mercurial/testing/storage.py	Tue Sep 18 16:45:13 2018 -0700
@@ -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)