ui: add support for fully printing chained exception stacks in ui.traceback()
Currently, only SubrepoAbort has a cause chained to it.
--- a/mercurial/ui.py Wed Feb 06 22:54:09 2013 -0500
+++ b/mercurial/ui.py Sat Feb 09 14:15:34 2013 -0500
@@ -686,11 +686,23 @@
only to call in exception handler. returns true if traceback
printed.'''
if self.tracebackflag:
- if exc:
+ if exc is None:
+ exc = sys.exc_info()
+ cause = getattr(exc[1], 'cause', None)
+
+ if cause is not None:
+ causetb = traceback.format_tb(cause[2])
+ exctb = traceback.format_tb(exc[2])
+ exconly = traceback.format_exception_only(cause[0], cause[1])
+
+ # exclude frame where 'exc' was chained and rethrown from exctb
+ self.write_err('Traceback (most recent call last):\n',
+ ''.join(exctb[:-1]),
+ ''.join(causetb),
+ ''.join(exconly))
+ else:
traceback.print_exception(exc[0], exc[1], exc[2],
file=self.ferr)
- else:
- traceback.print_exc(file=self.ferr)
return self.tracebackflag
def geteditor(self):
--- a/tests/test-subrepo.t Wed Feb 06 22:54:09 2013 -0500
+++ b/tests/test-subrepo.t Sat Feb 09 14:15:34 2013 -0500
@@ -771,6 +771,11 @@
abort: default path for subrepository not found (in subrepo sub/repo) (glob)
[255]
+Ensure a full traceback, not just the SubrepoAbort part
+
+ $ hg -R issue1852b update --traceback 2>&1 | grep 'raise util\.Abort'
+ raise util.Abort(_("default path for subrepository not found"))
+
Pull -u now doesn't help
$ hg -R issue1852b pull -u issue1852a