[PATCH 1 of 2 STABLE] hook: raise a more special HookAbort exception when a hook fails
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Sun Nov 30 03:35:57 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1417317215 28800
# Sat Nov 29 19:13:35 2014 -0800
# Branch stable
# Node ID 24883146c0e464584151b960c220572c80541529
# Parent edf29f9c15f0f171847f4c7a8184cca4e95c8b31
hook: raise a more special HookAbort exception when a hook fails
We need to gracefully handle some abort for pushkey, especially because it lead
to user-facing crash over the wireprotocols. So we needs a more specialised
exception to catch.
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -46,10 +46,16 @@ class Abort(Exception):
"""Raised if a command needs to print an error and exit."""
def __init__(self, *args, **kw):
Exception.__init__(self, *args)
self.hint = kw.get('hint')
+class HookAbort(Abort):
+ """raised when a validation hook fails aborting an operation
+
+ Exists to allow more specialized catching."""
+ pass
+
class ConfigError(Abort):
"""Exception raised when parsing config files"""
class OutOfBandError(Exception):
"""Exception raised when a remote repo reports failure"""
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -5,11 +5,11 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from i18n import _
import os, sys, time
-import extensions, util, demandimport
+import extensions, util, demandimport, error
def _pythonhook(ui, repo, name, hname, funcname, args, throw):
'''call python hook. hook is callable object, looked up as
name in python module. if callable returns "true", hook
fails, else passes. if hook raises exception, treated as
@@ -105,11 +105,11 @@ def _pythonhook(ui, repo, name, hname, f
duration = time.time() - starttime
ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n',
name, funcname, duration)
if r:
if throw:
- raise util.Abort(_('%s hook failed') % hname)
+ raise error.HookAbort(_('%s hook failed') % hname)
ui.warn(_('warning: %s hook failed\n') % hname)
return r
def _exthook(ui, repo, name, cmd, args, throw):
ui.note(_("running hook %s: %s\n") % (name, cmd))
@@ -140,11 +140,11 @@ def _exthook(ui, repo, name, cmd, args,
ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n',
name, cmd, duration)
if r:
desc, r = util.explainexit(r)
if throw:
- raise util.Abort(_('%s hook %s') % (name, desc))
+ raise error.HookAbort(_('%s hook %s') % (name, desc))
ui.warn(_('warning: %s hook %s\n') % (name, desc))
return r
def _allhooks(ui):
hooks = []
More information about the Mercurial-devel
mailing list