Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hook.py @ 9851:9e7b2c49d25d
Make it possible to debug failed hook imports via use of --traceback
Prior to this change, if a Python hook module failed to load (e.g. due
to an import error or path problem), it was impossible to figure out
why the error occurred, because the ImportErrors that got raised were
caught but never displayed.
If run with --traceback or ui.traceback=True, hg now prints tracebacks
of both of the ImportError instances that get raised before it bails.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 12 Nov 2009 14:05:52 -0800 |
parents | 852b1f3032d2 |
children | 37679dbf2ee3 |
line wrap: on
line diff
--- a/mercurial/hook.py Thu Nov 12 14:34:07 2009 -0600 +++ b/mercurial/hook.py Thu Nov 12 14:05:52 2009 -0800 @@ -37,10 +37,18 @@ try: obj = __import__(modname) except ImportError: + e1 = sys.exc_type, sys.exc_value, sys.exc_traceback try: # extensions are loaded with hgext_ prefix obj = __import__("hgext_%s" % modname) except ImportError: + e2 = sys.exc_type, sys.exc_value, sys.exc_traceback + if ui.tracebackflag: + ui.warn(_('exception from first failed import attempt:\n')) + ui.traceback(e1) + if ui.tracebackflag: + ui.warn(_('exception from second failed import attempt:\n')) + ui.traceback(e2) raise util.Abort(_('%s hook is invalid ' '(import of "%s" failed)') % (hname, modname))