]> granicus.if.org Git - python/commitdiff
Issue #16491: IDLE now prints chained exception tracebacks.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 9 Jan 2013 10:24:48 +0000 (12:24 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 9 Jan 2013 10:24:48 +0000 (12:24 +0200)
1  2 
Lib/idlelib/run.py
Misc/NEWS

index 9872af425179a0993f71b16298dc67b9ae9044eb,b0a47942311eb6e8ffa8d6f29f23edcd709ef5dd..dbf046bc5d36993ff4c37037143bf6d209185f4b
@@@ -171,15 -158,32 +171,34 @@@ def print_exception()
      efile = sys.stderr
      typ, val, tb = excinfo = sys.exc_info()
      sys.last_type, sys.last_value, sys.last_traceback = excinfo
-     tbe = traceback.extract_tb(tb)
-     print('Traceback (most recent call last):', file=efile)
-     exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
-                "RemoteDebugger.py", "bdb.py")
-     cleanup_traceback(tbe, exclude)
-     traceback.print_list(tbe, file=efile)
-     lines = traceback.format_exception_only(typ, val)
-     for line in lines:
-         print(line, end='', file=efile)
+     seen = set()
+     def print_exc(typ, exc, tb):
+         seen.add(exc)
+         context = exc.__context__
+         cause = exc.__cause__
+         if cause is not None and cause not in seen:
+             print_exc(type(cause), cause, cause.__traceback__)
+             print("\nThe above exception was the direct cause "
+                   "of the following exception:\n", file=efile)
 -        elif context is not None and context not in seen:
++        elif (context is not None and
++              not exc.__suppress_context__ and
++              context not in seen):
+             print_exc(type(context), context, context.__traceback__)
+             print("\nDuring handling of the above exception, "
+                   "another exception occurred:\n", file=efile)
+         if tb:
+             tbe = traceback.extract_tb(tb)
+             print('Traceback (most recent call last):', file=efile)
+             exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
+                        "RemoteDebugger.py", "bdb.py")
+             cleanup_traceback(tbe, exclude)
+             traceback.print_list(tbe, file=efile)
+         lines = traceback.format_exception_only(typ, exc)
+         for line in lines:
+             print(line, end='', file=efile)
+     print_exc(typ, val, tb)
  
  def cleanup_traceback(tb, exclude):
      "Remove excluded traces from beginning/end of tb; get cached lines"
diff --cc Misc/NEWS
index 8a5d14d443d3baa653635dfc4da0f14c02e88e00,029c93007d8fef042b7bcf87a49fbc9cd90837d9..e3fd61c8911bfa143affcb17d5f52963e96e105e
+++ b/Misc/NEWS
@@@ -139,11 -199,10 +139,13 @@@ Core and Builtin
  Library
  -------
  
 -- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
 -  Martin Packman.
+ - Issue #16491: IDLE now prints chained exception tracebacks.
 +- Issue #15972: Fix error messages when os functions expecting a file name or
 +  file descriptor receive the incorrect type.
 +
 +- Issue #16828: Fix error incorrectly raised by bz2.compress(b'') and
 +  bz2.BZ2Compressor.compress(b''). Initial patch by Martin Packman.
  
  - Issue #16541: tk_setPalette() now works with keyword arguments.