mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #767: safely encode SphinxErrors when printing to sys.stderr.
This commit is contained in:
parent
a4b8b81712
commit
c05063d0a5
@ -22,6 +22,7 @@ from sphinx.errors import SphinxError
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
||||
from sphinx.util.console import red, nocolor, color_terminal
|
||||
from sphinx.util.pycompat import terminal_safe
|
||||
|
||||
|
||||
def usage(argv, msg=None):
|
||||
@ -190,8 +191,7 @@ def main(argv):
|
||||
except KeyboardInterrupt:
|
||||
if use_pdb:
|
||||
import pdb
|
||||
print >>error, red('Interrupted while building, '
|
||||
'starting debugger:')
|
||||
print >>error, red('Interrupted while building, starting debugger:')
|
||||
traceback.print_exc()
|
||||
pdb.post_mortem(sys.exc_info()[2])
|
||||
return 1
|
||||
@ -199,17 +199,17 @@ def main(argv):
|
||||
if use_pdb:
|
||||
import pdb
|
||||
print >>error, red('Exception occurred while building, '
|
||||
'starting debugger:')
|
||||
'starting debugger:')
|
||||
traceback.print_exc()
|
||||
pdb.post_mortem(sys.exc_info()[2])
|
||||
else:
|
||||
print >>error
|
||||
if isinstance(err, SystemMessage):
|
||||
print >>error, red('reST markup error:')
|
||||
print >>error, err.args[0].encode('ascii', 'backslashreplace')
|
||||
print >>error, terminal_safe(err.args[0])
|
||||
elif isinstance(err, SphinxError):
|
||||
print >>error, red('%s:' % err.category)
|
||||
print >>error, err
|
||||
print >>error, terminal_safe(unicode(err))
|
||||
else:
|
||||
print >>error, red('Exception occurred:')
|
||||
print >>error, format_exception_cut_frames().rstrip()
|
||||
|
@ -27,6 +27,9 @@ if sys.version_info >= (3, 0):
|
||||
u = ''
|
||||
# StringIO/BytesIO classes
|
||||
from io import StringIO, BytesIO, TextIOWrapper
|
||||
# safely encode a string for printing to the terminal
|
||||
def terminal_safe(s):
|
||||
return s.encode('ascii', 'backslashreplace').decode('ascii')
|
||||
# support for running 2to3 over config files
|
||||
def convert_with_2to3(filepath):
|
||||
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
||||
@ -56,6 +59,9 @@ else:
|
||||
convert_with_2to3 = None
|
||||
def TextIOWrapper(stream, encoding):
|
||||
return codecs.lookup(encoding or 'ascii')[2](stream)
|
||||
# safely encode a string for printing to the terminal
|
||||
def terminal_safe(s):
|
||||
return s.encode('ascii', 'backslashreplace')
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user