From: William Stein Date: Sun, 22 Oct 2006 02:47:08 +0000 (-0700) Subject: Added nice error messages with context information. X-Git-Tag: 0.9.6.14~29^2~224 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f79b56550a3d6f2d53f9f35479daf7782589107a;p=cython.git Added nice error messages with context information. Finally, you can see the line itself where the error occured, instead of just the line number!! --- diff --git a/Cython/Compiler/Errors.py b/Cython/Compiler/Errors.py index 7381b067..070707d1 100644 --- a/Cython/Compiler/Errors.py +++ b/Cython/Compiler/Errors.py @@ -12,6 +12,13 @@ class PyrexError(Exception): class PyrexWarning(Exception): pass +def context(position): + F = open(position[0]).readlines() + s = ''.join(F[position[1]-6:position[1]]) + s += ' '*(position[2]-1) + '^' + s = '-'*60 + '\n...\n' + s + '\n' + '-'*60 + '\n' + return s + class CompileError(PyrexError): def __init__(self, position = None, message = ""): @@ -19,9 +26,11 @@ class CompileError(PyrexError): self.message = message if position: pos_str = "%s:%d:%d: " % position + cont = context(position) else: pos_str = "" - Exception.__init__(self, pos_str + message) + cont = '' + Exception.__init__(self, '\nError converting Pyrex file to C:\n' + cont + '\n' + pos_str + message ) class CompileWarning(PyrexWarning):