summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2001-06-27 14:07:50 (GMT)
committerThomas Wouters <thomas@python.org>2001-06-27 14:07:50 (GMT)
commitcde43be1051513a72e7d6cdf5a9a993c6ca9fe8e (patch)
tree12efe83bdf3d9c79c61342a5f513fe26af2e4dec
parent671e257d8d46e6e696435d3f029f4538dea93456 (diff)
downloadcpython-cde43be1051513a72e7d6cdf5a9a993c6ca9fe8e.zip
cpython-cde43be1051513a72e7d6cdf5a9a993c6ca9fe8e.tar.gz
cpython-cde43be1051513a72e7d6cdf5a9a993c6ca9fe8e.tar.bz2
Backport Tim's checkin 1.26 (patch probably by Michael Hudson, not Hundson):
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).
-rw-r--r--Lib/traceback.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index a758349..70b1606 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -171,19 +171,20 @@ def format_exception_only(etype, value):
if not filename: filename = "<string>"
list.append(' File "%s", line %d\n' %
(filename, lineno))
- i = 0
- while i < len(line) and line[i].isspace():
- i = i+1
- list.append(' %s\n' % line.strip())
- if offset is not None:
- s = ' '
- for c in line[i:offset-1]:
- if c.isspace():
- s = s + c
- else:
- s = s + ' '
- list.append('%s^\n' % s)
- value = msg
+ if line is not None:
+ i = 0
+ while i < len(line) and line[i].isspace():
+ i = i+1
+ list.append(' %s\n' % line.strip())
+ if offset is not None:
+ s = ' '
+ for c in line[i:offset-1]:
+ if c.isspace():
+ s = s + c
+ else:
+ s = s + ' '
+ list.append('%s^\n' % s)
+ value = msg
s = _some_str(value)
if s:
list.append('%s: %s\n' % (str(stype), s))