D11006: remotefilelog: stop using RuntimeError for control flow

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Wed Jul 7 18:12:33 UTC 2021


durin42 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We introduce a new exception to handle the various failure categories,
  rather than relying on RuntimeError.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/remotefilelog/basestore.py
  hgext/remotefilelog/shallowutil.py
  tests/test-remotefilelog-corrupt-cache.t

CHANGE DETAILS

diff --git a/tests/test-remotefilelog-corrupt-cache.t b/tests/test-remotefilelog-corrupt-cache.t
--- a/tests/test-remotefilelog-corrupt-cache.t
+++ b/tests/test-remotefilelog-corrupt-cache.t
@@ -38,7 +38,7 @@
   $ 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
+  hgext.remotefilelog.shallowutil.BadRemotefilelogHeader: unexpected remotefilelog header: illegal format
 
 Verify detection and remediation when remotefilelog.validatecachelog is set
 
diff --git a/hgext/remotefilelog/shallowutil.py b/hgext/remotefilelog/shallowutil.py
--- a/hgext/remotefilelog/shallowutil.py
+++ b/hgext/remotefilelog/shallowutil.py
@@ -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
 
 
diff --git a/hgext/remotefilelog/basestore.py b/hgext/remotefilelog/basestore.py
--- a/hgext/remotefilelog/basestore.py
+++ b/hgext/remotefilelog/basestore.py
@@ -308,7 +308,7 @@
                     # Content matches the intended path
                     return True
                 return False
-        except (ValueError, RuntimeError):
+        except (ValueError, shallowutil.BadRemotefilelogHeader):
             pass
 
         return False



To: durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list