Commit ca6995aa authored by Tim Peters's avatar Tim Peters

SF bug 431772: traceback.print_exc() causes traceback

Patch from Michael Hundson.
format_exception_only() blew up when trying to report a SyntaxError
from a string input (line is None in this case, but it assumed a string).
Bugfix candidate.
parent e3036d51
...@@ -171,19 +171,20 @@ def format_exception_only(etype, value): ...@@ -171,19 +171,20 @@ def format_exception_only(etype, value):
if not filename: filename = "<string>" if not filename: filename = "<string>"
list.append(' File "%s", line %d\n' % list.append(' File "%s", line %d\n' %
(filename, lineno)) (filename, lineno))
i = 0 if line is not None:
while i < len(line) and line[i].isspace(): i = 0
i = i+1 while i < len(line) and line[i].isspace():
list.append(' %s\n' % line.strip()) i = i+1
if offset is not None: list.append(' %s\n' % line.strip())
s = ' ' if offset is not None:
for c in line[i:offset-1]: s = ' '
if c.isspace(): for c in line[i:offset-1]:
s = s + c if c.isspace():
else: s = s + c
s = s + ' ' else:
list.append('%s^\n' % s) s = s + ' '
value = msg list.append('%s^\n' % s)
value = msg
s = _some_str(value) s = _some_str(value)
if s: if s:
list.append('%s: %s\n' % (str(stype), s)) list.append('%s: %s\n' % (str(stype), s))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment