1. mirror
  2. mercurial

Commits

Matt Harbison  committed 0062508

ui: add support for fully printing chained exception stacks in ui.traceback()

Currently, only SubrepoAbort has a cause chained to it.

  • Participants
  • Parent commits ca480d7
  • Branches default

Comments (0)

Files changed (2)

File mercurial/ui.py

View file
         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):

File tests/test-subrepo.t

View file
   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