From 80daa5b3895971a5fc0062674c24b7243129ae3a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 11 Jun 2008 16:38:01 +0200 Subject: [PATCH] do not print error context that resulted from encoding errors (i.e. it's unprintable anyway) --- Cython/Compiler/Errors.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Errors.py b/Cython/Compiler/Errors.py index 331ad921..42e139d3 100644 --- a/Cython/Compiler/Errors.py +++ b/Cython/Compiler/Errors.py @@ -17,10 +17,15 @@ def context(position): source = position[0] assert not (isinstance(source, unicode) or isinstance(source, str)), ( "Please replace filename strings with Scanning.FileSourceDescriptor instances %r" % source) - F = list(source.get_lines()) - s = ''.join(F[max(0, position[1]-6):position[1]]) - s += ' '*(position[2]-1) + '^' - s = '-'*60 + '\n...\n' + s + '\n' + '-'*60 + '\n' + try: + F = list(source.get_lines()) + except UnicodeDecodeError: + # 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 class CompileError(PyrexError): -- 2.26.2