hook: raise a more specialized HookAbort exception when a hook fails
We need to gracefully handle some aborts for pushkey, especially
because it leads to a user-facing crash over the wireprotocols. So we
need a more specialized exception to catch.
--- a/mercurial/error.py Mon Dec 01 15:04:34 2014 -0600
+++ b/mercurial/error.py Sat Nov 29 19:13:35 2014 -0800
@@ -48,6 +48,12 @@
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"""
--- a/mercurial/hook.py Mon Dec 01 15:04:34 2014 -0600
+++ b/mercurial/hook.py Sat Nov 29 19:13:35 2014 -0800
@@ -7,7 +7,7 @@
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
@@ -107,7 +107,7 @@
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
@@ -142,7 +142,7 @@
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