# HG changeset patch # User Gregory Szorc # Date 1537314429 25200 # Node ID b63dee7bd0d9b1bf39116d0f79865ab239d883c7 # Parent cb65d4b7e429b1ab9824cfaafc85a220b00760a3 global: replace most uses of RevlogError with StorageError (API) When catching errors in storage, we should be catching StorageError instead of RevlogError. When throwing errors related to storage, we shouldn't be using RevlogError unless we know the error stemmed from revlogs. And we only reliably know that if we're in revlog.py or are inheriting from a type defined in revlog.py. Differential Revision: https://phab.mercurial-scm.org/D4655 diff -r cb65d4b7e429 -r b63dee7bd0d9 hgext/lfs/blobstore.py --- a/hgext/lfs/blobstore.py Tue Sep 18 16:45:13 2018 -0700 +++ b/hgext/lfs/blobstore.py Tue Sep 18 16:47:09 2018 -0700 @@ -586,7 +586,7 @@ raise error.Abort(_('lfs: unknown url scheme: %s') % scheme) return _storemap[scheme](repo, url) -class LfsRemoteError(error.RevlogError): +class LfsRemoteError(error.StorageError): pass class LfsCorruptionError(error.Abort): diff -r cb65d4b7e429 -r b63dee7bd0d9 hgext/lfs/pointer.py --- a/hgext/lfs/pointer.py Tue Sep 18 16:45:13 2018 -0700 +++ b/hgext/lfs/pointer.py Tue Sep 18 16:47:09 2018 -0700 @@ -19,7 +19,7 @@ stringutil, ) -class InvalidPointer(error.RevlogError): +class InvalidPointer(error.StorageError): pass class gitlfspointer(dict): diff -r cb65d4b7e429 -r b63dee7bd0d9 hgext/transplant.py --- a/hgext/transplant.py Tue Sep 18 16:45:13 2018 -0700 +++ b/hgext/transplant.py Tue Sep 18 16:47:09 2018 -0700 @@ -503,7 +503,7 @@ def hasnode(repo, node): try: return repo.changelog.rev(node) is not None - except error.RevlogError: + except error.StorageError: return False def browserevs(ui, repo, nodes, opts): diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/changelog.py --- a/mercurial/changelog.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/changelog.py Tue Sep 18 16:47:09 2018 -0700 @@ -513,10 +513,10 @@ # revision text contain two "\n\n" sequences -> corrupt # repository since read cannot unpack the revision. if not user: - raise error.RevlogError(_("empty username")) + raise error.StorageError(_("empty username")) if "\n" in user: - raise error.RevlogError(_("username %r contains a newline") - % pycompat.bytestr(user)) + raise error.StorageError(_("username %r contains a newline") + % pycompat.bytestr(user)) desc = stripdesc(desc) @@ -529,8 +529,8 @@ if branch in ("default", ""): del extra["branch"] elif branch in (".", "null", "tip"): - raise error.RevlogError(_('the name \'%s\' is reserved') - % branch) + raise error.StorageError(_('the name \'%s\' is reserved') + % branch) if extra: extra = encodeextra(extra) parseddate = "%s %s" % (parseddate, extra) diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/error.py --- a/mercurial/error.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/error.py Tue Sep 18 16:47:09 2018 -0700 @@ -283,7 +283,7 @@ Abort.__init__(self, 'failed to update value for "%s/%s"' % (namespace, key)) -class CensoredNodeError(RevlogError): +class CensoredNodeError(StorageError): """error raised when content verification fails on a censored node Also contains the tombstone data substituted for the uncensored data. @@ -291,10 +291,10 @@ def __init__(self, filename, node, tombstone): from .node import short - RevlogError.__init__(self, '%s:%s' % (filename, short(node))) + StorageError.__init__(self, '%s:%s' % (filename, short(node))) self.tombstone = tombstone -class CensoredBaseError(RevlogError): +class CensoredBaseError(StorageError): """error raised when a delta is rejected because its base is censored A delta based on a censored revision must be formed as single patch diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/hgweb/hgweb_mod.py Tue Sep 18 16:47:09 2018 -0700 @@ -435,7 +435,7 @@ res.status = '404 Not Found' res.headers['Content-Type'] = ctype return rctx.sendtemplate('error', error=msg) - except (error.RepoError, error.RevlogError) as e: + except (error.RepoError, error.StorageError) as e: res.status = '500 Internal Server Error' res.headers['Content-Type'] = ctype return rctx.sendtemplate('error', error=pycompat.bytestr(e)) diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/manifest.py --- a/mercurial/manifest.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/manifest.py Tue Sep 18 16:47:09 2018 -0700 @@ -643,7 +643,7 @@ """Check filenames for illegal characters.""" for f in l: if '\n' in f or '\r' in f: - raise error.RevlogError( + raise error.StorageError( _("'\\n' and '\\r' disallowed in filenames: %r") % pycompat.bytestr(f)) diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/revlogutils/deltas.py --- a/mercurial/revlogutils/deltas.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/revlogutils/deltas.py Tue Sep 18 16:47:09 2018 -0700 @@ -457,7 +457,8 @@ if validatehash: revlog.checkhash(fulltext, expectednode, p1=p1, p2=p2) if flags & REVIDX_ISCENSORED: - raise error.RevlogError(_('node %s is not censored') % expectednode) + raise error.StorageError(_('node %s is not censored') % + expectednode) except error.CensoredNodeError: # must pass the censored index flag to add censored revisions if not flags & REVIDX_ISCENSORED: diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/scmutil.py --- a/mercurial/scmutil.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/scmutil.py Tue Sep 18 16:47:09 2018 -0700 @@ -207,7 +207,7 @@ ui.error("\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) except error.CensoredNodeError as inst: ui.error(_("abort: file censored %s!\n") % inst) - except error.RevlogError as inst: + except error.StorageError as inst: ui.error(_("abort: %s!\n") % inst) except error.InterventionRequired as inst: ui.error("%s\n" % inst) diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/util.py --- a/mercurial/util.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/util.py Tue Sep 18 16:47:09 2018 -0700 @@ -3448,7 +3448,7 @@ The object has a ``decompress(data)`` method that decompresses data. The method will only be called if ``data`` begins with ``revlogheader()``. The method should return the raw, uncompressed - data or raise a ``RevlogError``. + data or raise a ``StorageError``. The object is reusable but is not thread safe. """ @@ -3626,8 +3626,8 @@ try: return zlib.decompress(data) except zlib.error as e: - raise error.RevlogError(_('revlog decompress error: %s') % - stringutil.forcebytestr(e)) + raise error.StorageError(_('revlog decompress error: %s') % + stringutil.forcebytestr(e)) def revlogcompressor(self, opts=None): return self.zlibrevlogcompressor() @@ -3838,8 +3838,8 @@ return ''.join(chunks) except Exception as e: - raise error.RevlogError(_('revlog decompress error: %s') % - stringutil.forcebytestr(e)) + raise error.StorageError(_('revlog decompress error: %s') % + stringutil.forcebytestr(e)) def revlogcompressor(self, opts=None): opts = opts or {} diff -r cb65d4b7e429 -r b63dee7bd0d9 mercurial/verify.py --- a/mercurial/verify.py Tue Sep 18 16:45:13 2018 -0700 +++ b/mercurial/verify.py Tue Sep 18 16:47:09 2018 -0700 @@ -360,7 +360,7 @@ try: fl = repo.file(f) - except error.RevlogError as e: + except error.StorageError as e: self.err(lr, _("broken revlog! (%s)") % e, f) continue diff -r cb65d4b7e429 -r b63dee7bd0d9 tests/simplestorerepo.py --- a/tests/simplestorerepo.py Tue Sep 18 16:45:13 2018 -0700 +++ b/tests/simplestorerepo.py Tue Sep 18 16:47:09 2018 -0700 @@ -61,6 +61,9 @@ if not isinstance(rev, int): raise ValueError('expected int') +class simplestoreerror(error.StorageError): + pass + @interfaceutil.implementer(repository.irevisiondelta) @attr.s(slots=True, frozen=True) class simplestorerevisiondelta(object): @@ -261,8 +264,8 @@ return text, True if flags & ~revlog.REVIDX_KNOWN_FLAGS: - raise error.RevlogError(_("incompatible revision flag '%#x'") % - (flags & ~revlog.REVIDX_KNOWN_FLAGS)) + raise simplestoreerror(_("incompatible revision flag '%#x'") % + (flags & ~revlog.REVIDX_KNOWN_FLAGS)) validatehash = True # Depending on the operation (read or write), the order might be @@ -279,7 +282,7 @@ if flag not in revlog._flagprocessors: message = _("missing processor for flag '%#x'") % (flag) - raise error.RevlogError(message) + raise simplestoreerror(message) processor = revlog._flagprocessors[flag] if processor is not None: @@ -299,7 +302,7 @@ if p1 is None and p2 is None: p1, p2 = self.parents(node) if node != revlog.hash(text, p1, p2): - raise error.RevlogError(_("integrity check failed on %s") % + raise simplestoreerror(_("integrity check failed on %s") % self._path) def revision(self, node, raw=False):