[PATCH 1 of 6 mergedriver] hook: raise a separate exception for when loading a hook fails
Augie Fackler
raf at durin42.com
Thu Oct 15 08:56:26 CDT 2015
On Wed, Oct 14, 2015 at 04:52:29PM -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1444700963 25200
> # Mon Oct 12 18:49:23 2015 -0700
> # Node ID 2a42915e11423eaa1e127e12333a890655c8bb76
> # Parent 07db7e95c464537aeb2dd7aba39de0813eaffd04
> hook: raise a separate exception for when loading a hook fails
This one was obvious enough I took it, but I think someone with more
context (marmoute) should look at the rest of the stack.
>
> For easier catching.
>
> diff --git a/mercurial/error.py b/mercurial/error.py
> --- a/mercurial/error.py
> +++ b/mercurial/error.py
> @@ -57,6 +57,12 @@ class Abort(HintException):
> """Raised if a command needs to print an error and exit."""
> pass
>
> +class HookLoadError(Abort):
> + """raised when loading a hook fails, aborting an operation
> +
> + Exists to allow more specialized catching."""
> + pass
> +
> class HookAbort(Abort):
> """raised when a validation hook fails, aborting an operation
>
> diff --git a/mercurial/hook.py b/mercurial/hook.py
> --- a/mercurial/hook.py
> +++ b/mercurial/hook.py
> @@ -35,8 +35,9 @@ def _pythonhook(ui, repo, name, hname, f
> else:
> d = funcname.rfind('.')
> if d == -1:
> - raise error.Abort(_('%s hook is invalid ("%s" not in '
> - 'a module)') % (hname, funcname))
> + raise error.HookLoadError(
> + _('%s hook is invalid ("%s" not in a module)')
> + % (hname, funcname))
> modname = funcname[:d]
> oldpaths = sys.path
> if util.mainfrozen():
> @@ -63,21 +64,21 @@ def _pythonhook(ui, repo, name, hname, f
> ui.warn(_('exception from second failed import '
> 'attempt:\n'))
> ui.traceback(e2)
> - raise error.Abort(_('%s hook is invalid '
> - '(import of "%s" failed)') %
> - (hname, modname))
> + raise error.HookLoadError(
> + _('%s hook is invalid (import of "%s" failed)') %
> + (hname, modname))
> sys.path = oldpaths
> try:
> for p in funcname.split('.')[1:]:
> obj = getattr(obj, p)
> except AttributeError:
> - raise error.Abort(_('%s hook is invalid '
> - '("%s" is not defined)') %
> - (hname, funcname))
> + raise error.HookLoadError(
> + _('%s hook is invalid ("%s" is not defined)')
> + % (hname, funcname))
> if not callable(obj):
> - raise error.Abort(_('%s hook is invalid '
> - '("%s" is not callable)') %
> - (hname, funcname))
> + raise error.HookLoadError(
> + _('%s hook is invalid ("%s" is not callable)')
> + % (hname, funcname))
>
> ui.note(_("calling hook %s: %s\n") % (hname, funcname))
> starttime = time.time()
> diff --git a/tests/test-hook.t b/tests/test-hook.t
> --- a/tests/test-hook.t
> +++ b/tests/test-hook.t
> @@ -628,7 +628,7 @@ make sure --traceback works on hook impo
> Traceback (most recent call last):
> ImportError: No module named hgext_importfail
> Traceback (most recent call last):
> - Abort: precommit.importfail hook is invalid (import of "importfail" failed)
> + HookLoadError: precommit.importfail hook is invalid (import of "importfail" failed)
> abort: precommit.importfail hook is invalid (import of "importfail" failed)
>
> Issue1827: Hooks Update & Commit not completely post operation
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list