changeset 28080:37b818cad146

hook: for python hook ImportErrors, add note to run with --traceback I personally found it completely non-obvious that --traceback prints out stack traces for failed imports.
author Siddharth Agarwal <sid0@fb.com>
date Thu, 11 Feb 2016 22:52:23 -0800
parents 0c9e914029be
children a6344df5108e
files mercurial/hook.py tests/test-hook.t
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hook.py	Thu Feb 11 22:41:20 2016 -0800
+++ b/mercurial/hook.py	Thu Feb 11 22:52:23 2016 -0800
@@ -64,9 +64,15 @@
                         ui.warn(_('exception from second failed import '
                                   'attempt:\n'))
                     ui.traceback(e2)
+
+                    if not ui.tracebackflag:
+                        tracebackhint = _(
+                            'run with --traceback for stack trace')
+                    else:
+                        tracebackhint = None
                     raise error.HookLoadError(
                         _('%s hook is invalid: import of "%s" failed') %
-                        (hname, modname))
+                        (hname, modname), hint=tracebackhint)
         sys.path = oldpaths
         try:
             for p in funcname.split('.')[1:]:
--- a/tests/test-hook.t	Thu Feb 11 22:41:20 2016 -0800
+++ b/tests/test-hook.t	Thu Feb 11 22:52:23 2016 -0800
@@ -505,6 +505,7 @@
   pulling from ../a
   searching for changes
   abort: preoutgoing.badmodule hook is invalid: import of "nomodule" failed
+  (run with --traceback for stack trace)
   [255]
 
   $ echo '[hooks]' > ../a/.hg/hgrc
@@ -513,6 +514,7 @@
   pulling from ../a
   searching for changes
   abort: preoutgoing.unreachable hook is invalid: import of "hooktests.container" failed
+  (run with --traceback for stack trace)
   [255]
 
   $ echo '[hooks]' > ../a/.hg/hgrc