Improved formatting of TypeErrors encountered in ctml_writer.py

This commit is contained in:
Ray Speth 2012-04-04 18:45:07 +00:00
parent 47f3bac7ae
commit 02ccf4f715

View file

@ -2368,6 +2368,25 @@ def convert(filename):
print ' '* (err.offset+9) + '^'
print
sys.exit(3)
except TypeError as err:
import traceback
text = open(filename).readlines()
tb = traceback.extract_tb(sys.exc_info()[2])
lineno = tb[-1][1]
print '%s on line %i of %s:' % (err.__class__.__name__, lineno, filename)
print err
print '\n| Line |'
for i in range(max(lineno-6, 0),
min(lineno+3, len(text))):
if i == lineno-1:
print '> % 4i >' % (i+1), text[i].rstrip()
else:
print '| % 4i |' % (i+1), text[i].rstrip()
sys.exit(4)
write()