Patchwork [1,of,8,V2] obsolete: raise richer exception on unknown version

login
register
mail settings
Submitter Pierre-Yves David
Date May 28, 2017, 10:54 p.m.
Message ID <63c085e9e36cb5b32b93.1496012068@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21010/
State Accepted
Headers show

Comments

Pierre-Yves David - May 28, 2017, 10:54 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1495723823 -7200
#      Thu May 25 16:50:23 2017 +0200
# Node ID 63c085e9e36cb5b32b9358889424ee77294f7fc9
# Parent  b62b2b373bced626dda563cf5cabb64ea752c9e4
# EXP-Topic obsstrip
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 63c085e9e36c
obsolete: raise richer exception on unknown version

We raise a more precise subclass of Abort with details about the faulty
version.  This will be used to detect this case  and display some information
in debugbundle.

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -138,6 +138,14 @@  class UnsupportedMergeRecords(Abort):
             hint=_('see https://mercurial-scm.org/wiki/MergeStateRecords for '
                    'more information'))
 
+class UnknownVersion(Abort):
+    """generic exception for aborting from an encounter with an unknown version
+    """
+
+    def __init__(self, msg, hint=None, version=None):
+        self.version = version
+        super(UnknownVersion, self).__init__(msg, hint=hint)
+
 class LockError(IOError):
     def __init__(self, errno, strerror, filename, desc):
         IOError.__init__(self, errno, strerror, filename)
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -446,8 +446,8 @@  def _readmarkers(data):
     diskversion = _unpack('>B', data[off:off + 1])[0]
     off += 1
     if diskversion not in formats:
-        raise error.Abort(_('parsing obsolete marker: unknown version %r')
-                         % diskversion)
+        msg = _('parsing obsolete marker: unknown version %r') % diskversion
+        raise error.UnknownVersion(msg, version=diskversion)
     return diskversion, formats[diskversion][0](data, off)
 
 def encodemarkers(markers, addheader=False, version=_fm0version):