changeset 40003:ad8389ecd3f5

storageutil: consistently raise LookupError (API) The interface docs say this is supposed to raise LookupError on failure. But for invalid revision number input, it could raise IndexError because ifileindex.node() is documented to raise IndexError. lookup() for files isn't used that much (pretty much just in basefilectx in core AFAICT). And callers should already be catching LookupError. So I don't anticipate that much fallout from this change. Differential Revision: https://phab.mercurial-scm.org/D4798
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:16:44 -0700
parents 0e8836be9541
children fa3dc85a747e
files mercurial/testing/storage.py mercurial/utils/storageutil.py
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/testing/storage.py	Fri Sep 28 11:03:17 2018 -0700
+++ b/mercurial/testing/storage.py	Fri Sep 28 11:16:44 2018 -0700
@@ -199,13 +199,13 @@
         with self.assertRaises(error.LookupError):
             f.lookup(hex(node)[0:12])
 
-        with self.assertRaises(IndexError):
+        with self.assertRaises(error.LookupError):
             f.lookup(-2)
 
         with self.assertRaises(error.LookupError):
             f.lookup(b'-2')
 
-        with self.assertRaises(IndexError):
+        with self.assertRaises(error.LookupError):
             f.lookup(1)
 
         with self.assertRaises(error.LookupError):
--- a/mercurial/utils/storageutil.py	Fri Sep 28 11:03:17 2018 -0700
+++ b/mercurial/utils/storageutil.py	Fri Sep 28 11:16:44 2018 -0700
@@ -121,7 +121,10 @@
     Raises ``error.LookupError`` on failure.
     """
     if isinstance(fileid, int):
-        return store.node(fileid)
+        try:
+            return store.node(fileid)
+        except IndexError:
+            raise error.LookupError(fileid, identifier, _('no match found'))
 
     if len(fileid) == 20:
         try: