[PATCH RFC STABLE] introduce new RequirementError (issue2649)
Adrian Buehlmann
adrian at cadifra.com
Fri Feb 18 21:55:58 UTC 2011
On 2011-02-18 21:58, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1298057125 -3600
> # Branch stable
> # Node ID eee8ff74d9d09f0da56db07c0799397839772ef1
> # Parent d724a69309e0ce9a7d8efb13e11ba45a4c85045c
> introduce new RequirementError (issue2649)
>
> We do not inherit from RepoError to make sure this error is not caught by
> "except error.RepoError" blocks like in dispatch.py line 581, so we can
> avoid obscuring the original error message, which explicitly mentions the
> unknown requirement ("requirement ... not supported").
>
> RequirementError is a non-recoverable error.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -94,6 +94,8 @@ def _runcatch(ui, args):
> else:
> ui.warn(_("hg: %s\n") % inst.args[1])
> commands.help_(ui, 'shortlist')
> + except error.RequirementError, inst:
> + ui.warn(_("abort: %s!\n") % inst)
> except error.RepoError, inst:
> ui.warn(_("abort: %s!\n") % inst)
> except error.ResponseError, inst:
> diff --git a/mercurial/error.py b/mercurial/error.py
> --- a/mercurial/error.py
> +++ b/mercurial/error.py
> @@ -51,6 +51,11 @@ class RepoLookupError(RepoError):
> class CapabilityError(RepoError):
> pass
>
> +class RequirementError(Exception):
> + """Exception raised if .hg/requires has an unknown entry.
> + Intentionally not inherited from RepoError"""
> + pass
> +
I must say I'm not really sure about whether RequirementError should
inherit from RepoError or not.
Thus the RFC tag.
Iff it would inherit from RepoError, then something like
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -576,6 +576,8 @@ def _dispatch(ui, args):
if not repo.local():
raise util.Abort(_("repository '%s' is not local") % path)
ui.setconfig("bundle", "mainreporoot", repo.root)
+ except error.RequirementError:
+ raise
except error.RepoError:
if cmd not in commands.optionalrepo.split():
if args and not path: # try to infer -R from command args
for dispatch.py would be needed to make sure the RequirementError is not
sucked up by the "except error.RepoError" handler block.
> class LockError(IOError):
> def __init__(self, errno, strerror, filename, desc):
> IOError.__init__(self, errno, strerror, filename)
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -75,7 +75,8 @@ class localrepository(repo.repository):
> if inst.errno != errno.ENOENT:
> raise
> for r in requirements - self.supported:
> - raise error.RepoError(_("requirement '%s' not supported") % r)
> + raise error.RequirementError(
> + _("requirement '%s' not supported") % r)
>
> self.sharedpath = self.path
> try:
> diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
> --- a/mercurial/statichttprepo.py
> +++ b/mercurial/statichttprepo.py
> @@ -112,7 +112,8 @@ class statichttprepository(localrepo.loc
> # check them
> for r in requirements:
> if r not in self.supported:
> - raise error.RepoError(_("requirement '%s' not supported") % r)
> + raise error.RequirementError(
> + _("requirement '%s' not supported") % r)
>
> # setup store
> self.store = store.store(requirements, self.path, opener)
> diff --git a/tests/test-commit.t b/tests/test-commit.t
> --- a/tests/test-commit.t
> +++ b/tests/test-commit.t
> @@ -92,6 +92,15 @@ An empty date was interpreted as epoch o
> $ hg commit -d '' -m commit-no-date
> $ hg tip --template '{date|isodate}\n' | grep '1970'
> [1]
> +
> +Make sure we do not obscure unknown requires file entries (issue2649)
> +
> + $ echo foo >> foo
> + $ echo fake >> .hg/requires
> + $ hg commit -m bla
> + abort: requirement 'fake' not supported!
> + [255]
> +
> $ cd ..
>
>
> diff --git a/tests/test-identify.t b/tests/test-identify.t
> --- a/tests/test-identify.t
> +++ b/tests/test-identify.t
> @@ -67,3 +67,11 @@ remote with tags?
> $ hg id -t http://localhost:$HGPORT1/
> abort: can't query remote revision number, branch, or tags
> [255]
> +
> +Make sure we do not obscure unknown requires file entries (issue2649)
> +
> + $ echo fake >> .hg/requires
> + $ hg id
> + abort: requirement 'fake' not supported!
> + [255]
> +
More information about the Mercurial-devel
mailing list