changeset 47549:e972077600e5

remotefilelog: stop using RuntimeError for control flow We introduce a new exception to handle the various failure categories, rather than relying on RuntimeError. Differential Revision: https://phab.mercurial-scm.org/D11006
author Augie Fackler <augie@google.com>
date Wed, 07 Jul 2021 11:45:17 -0400
parents 5830539c46be
children db31bafa4ae3
files hgext/remotefilelog/basestore.py hgext/remotefilelog/shallowutil.py tests/test-remotefilelog-corrupt-cache.t
diffstat 3 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotefilelog/basestore.py	Wed Jul 07 13:20:47 2021 -0400
+++ b/hgext/remotefilelog/basestore.py	Wed Jul 07 11:45:17 2021 -0400
@@ -308,7 +308,7 @@
                     # Content matches the intended path
                     return True
                 return False
-        except (ValueError, RuntimeError):
+        except (ValueError, shallowutil.BadRemotefilelogHeader):
             pass
 
         return False
--- a/hgext/remotefilelog/shallowutil.py	Wed Jul 07 13:20:47 2021 -0400
+++ b/hgext/remotefilelog/shallowutil.py	Wed Jul 07 11:45:17 2021 -0400
@@ -233,6 +233,10 @@
     return x
 
 
+class BadRemotefilelogHeader(error.StorageError):
+    """Exception raised when parsing a remotefilelog blob header fails."""
+
+
 def parsesizeflags(raw):
     """given a remotefilelog blob, return (headersize, rawtextsize, flags)
 
@@ -253,16 +257,20 @@
                     elif s.startswith(constants.METAKEYFLAG):
                         flags = int(s[len(constants.METAKEYFLAG) :])
             else:
-                raise RuntimeError(
+                raise BadRemotefilelogHeader(
                     b'unsupported remotefilelog header: %s' % header
                 )
         else:
             # v0, str(int(size)) is the header
             size = int(header)
     except ValueError:
-        raise RuntimeError("unexpected remotefilelog header: illegal format")
+        raise BadRemotefilelogHeader(
+            "unexpected remotefilelog header: illegal format"
+        )
     if size is None:
-        raise RuntimeError("unexpected remotefilelog header: no size found")
+        raise BadRemotefilelogHeader(
+            "unexpected remotefilelog header: no size found"
+        )
     return index + 1, size, flags
 
 
--- a/tests/test-remotefilelog-corrupt-cache.t	Wed Jul 07 13:20:47 2021 -0400
+++ b/tests/test-remotefilelog-corrupt-cache.t	Wed Jul 07 11:45:17 2021 -0400
@@ -38,7 +38,8 @@
   $ chmod u+w $CACHEDIR/master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0
   $ echo x > $CACHEDIR/master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0
   $ hg up tip 2>&1 | egrep "^[^ ].*unexpected remotefilelog"
-  RuntimeError: unexpected remotefilelog header: illegal format
+  abort: unexpected remotefilelog header: illegal format (no-py3 !)
+  hgext.remotefilelog.shallowutil.BadRemotefilelogHeader: unexpected remotefilelog header: illegal format (py3 !)
 
 Verify detection and remediation when remotefilelog.validatecachelog is set