Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ui.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 | 951730b2b8ba |
children | 38170eeed18c 500d09be7ace |
line wrap: on
line diff
--- a/mercurial/ui.py Thu Nov 12 14:34:07 2009 -0600 +++ b/mercurial/ui.py Thu Nov 12 14:05:52 2009 -0800 @@ -15,7 +15,7 @@ class ui(object): def __init__(self, src=None): self._buffers = [] - self.quiet = self.verbose = self.debugflag = self._traceback = False + self.quiet = self.verbose = self.debugflag = self.tracebackflag = False self._reportuntrusted = True self._ocfg = config.config() # overlay self._tcfg = config.config() # trusted @@ -101,7 +101,7 @@ if self.verbose and self.quiet: self.quiet = self.verbose = False self._reportuntrusted = self.configbool("ui", "report_untrusted", True) - self._traceback = self.configbool('ui', 'traceback', False) + self.tracebackflag = self.configbool('ui', 'traceback', False) # update trust information self._trustusers.update(self.configlist('trusted', 'users')) @@ -337,13 +337,16 @@ return t - def traceback(self): + def traceback(self, exc=None): '''print exception traceback if traceback printing enabled. only to call in exception handler. returns true if traceback printed.''' - if self._traceback: - traceback.print_exc() - return self._traceback + if self.tracebackflag: + if exc: + traceback.print_exception(exc[0], exc[1], exc[2]) + else: + traceback.print_exc() + return self.tracebackflag def geteditor(self): '''return editor to use'''