Improved formatting of TypeErrors encountered in ctml_writer.py
This commit is contained in:
parent
47f3bac7ae
commit
02ccf4f715
1 changed files with 19 additions and 0 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue