Commits

Jon Waltman committed 3c49758

Issue #869: Add option ``-T`` for printing the full traceback on exception.

Comments (0)

Files changed (2)

 Release 1.2 (in development)
 ============================
 
+* #869: sphinx-build now has the option :option:`-T` for printing the full
+  traceback after an unhandled exception.
+
 * #940: Fix gettext does not extract figure caption.
 
 * #1067: Improve the ordering of the JavaScript search results: matches in titles

sphinx/cmdline.py

          -w <file> -- write warnings (and errors) to given file
          -W        -- turn warnings into errors
          -P        -- run Pdb on exception
+         -T        -- show full traceback on exception
 Modi:
 * without -a and without filenames, write new and changed files.
 * with -a, write all files.
         nocolor()
 
     try:
-        opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:ng:NEqQWw:P')
+        opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:ng:NEqQWw:PT')
         allopts = set(opt[0] for opt in opts)
         srcdir = confdir = abspath(args[0])
         if not path.isdir(srcdir):
 
     buildername = None
     force_all = freshenv = warningiserror = use_pdb = False
+    show_traceback = False
     status = sys.stdout
     warning = sys.stderr
     error = sys.stderr
             warnfile = val
         elif opt == '-P':
             use_pdb = True
+        elif opt == '-T':
+            show_traceback = True
 
     if warning and warnfile:
         warnfp = open(warnfile, 'w')
                      warningiserror, tags)
         app.build(force_all, filenames)
         return app.statuscode
-    except KeyboardInterrupt:
-        if use_pdb:
-            import pdb
-            print >>error, red('Interrupted while building, starting debugger:')
-            traceback.print_exc()
-            pdb.post_mortem(sys.exc_info()[2])
-        return 1
-    except Exception, err:
+    except (Exception, KeyboardInterrupt), err:
         if use_pdb:
             import pdb
             print >>error, red('Exception occurred while building, '
             pdb.post_mortem(sys.exc_info()[2])
         else:
             print >>error
-            if isinstance(err, SystemMessage):
+            if show_traceback:
+                traceback.print_exc(None, error)
+                print >>error
+            if isinstance(err, KeyboardInterrupt):
+                print >>error, 'interrupted!'
+            elif isinstance(err, SystemMessage):
                 print >>error, red('reST markup error:')
                 print >>error, terminal_safe(err.args[0])
             elif isinstance(err, SphinxError):