Commit 80daa5b3 authored by Stefan Behnel's avatar Stefan Behnel

do not print error context that resulted from encoding errors (i.e. it's unprintable anyway)

parent 761641ea
...@@ -17,10 +17,15 @@ def context(position): ...@@ -17,10 +17,15 @@ def context(position):
source = position[0] source = position[0]
assert not (isinstance(source, unicode) or isinstance(source, str)), ( assert not (isinstance(source, unicode) or isinstance(source, str)), (
"Please replace filename strings with Scanning.FileSourceDescriptor instances %r" % source) "Please replace filename strings with Scanning.FileSourceDescriptor instances %r" % source)
F = list(source.get_lines()) try:
s = ''.join(F[max(0, position[1]-6):position[1]]) F = list(source.get_lines())
s += ' '*(position[2]-1) + '^' except UnicodeDecodeError:
s = '-'*60 + '\n...\n' + s + '\n' + '-'*60 + '\n' # file has an encoding problem
s = "[unprintable code]\n"
else:
s =''.join(F[max(0, position[1]-6):position[1]])
s = '...\n' + s + ' '*(position[2]-1) + '^\n'
s = '-'*60 + '\n' + s + '-'*60 + '\n'
return s return s
class CompileError(PyrexError): class CompileError(PyrexError):
......
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