Patchwork [3,of,3] hook: for python hook ImportErrors, add note to run with --traceback

login
register
mail settings
Submitter Siddharth Agarwal
Date Feb. 12, 2016, 7:04 a.m.
Message ID <d1930111ddf8c6fab4f0.1455260653@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/13125/
State Accepted
Headers show

Comments

Siddharth Agarwal - Feb. 12, 2016, 7:04 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1455259943 28800
#      Thu Feb 11 22:52:23 2016 -0800
# Node ID d1930111ddf8c6fab4f058d3ff0400f85abcd247
# Parent  da66d8660fc331fe4d73298fa497cff3a830fa6b
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r d1930111ddf8
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.
Pierre-Yves David - Feb. 12, 2016, 2:31 p.m.
On 02/12/2016 07:04 AM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1455259943 28800
> #      Thu Feb 11 22:52:23 2016 -0800
> # Node ID d1930111ddf8c6fab4f058d3ff0400f85abcd247
> # Parent  da66d8660fc331fe4d73298fa497cff3a830fa6b
> # Available At http://42.netv6.net/sid0-wip/hg/
> #              hg pull http://42.netv6.net/sid0-wip/hg/ -r d1930111ddf8
> hook: for python hook ImportErrors, add note to run with --traceback

Pushed to the clowncopter, Thanks!

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -64,9 +64,15 @@  def _pythonhook(ui, repo, name, hname, f
                         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:]:
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -505,6 +505,7 @@  test python hooks
   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 @@  test python hooks
   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