From: Robert Bradshaw Date: Thu, 9 Dec 2010 11:05:20 +0000 (-0800) Subject: Fix fatal errors + nice exception traceback interaction. X-Git-Tag: 0.14.beta0~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=75c3536ef1ba8fcdace71926ba9e01763db12e6a;p=cython.git Fix fatal errors + nice exception traceback interaction. --- diff --git a/Cython/Compiler/Errors.py b/Cython/Compiler/Errors.py index e2ec1d9e..38232ba7 100644 --- a/Cython/Compiler/Errors.py +++ b/Cython/Compiler/Errors.py @@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning): # self.message = message Exception.__init__(self, format_position(position) + message) - class InternalError(Exception): # If this is ever raised, there is a bug in the compiler. @@ -70,6 +69,12 @@ class InternalError(Exception): Exception.__init__(self, u"Internal compiler error: %s" % message) +class AbortError(Exception): + # Throw this to stop the compilation immediately. + + def __init__(self, message): + self.message_only = message + Exception.__init__(self, u"Abort error: %s" % message) class CompilerCrash(CompileError): # raised when an unexpected exception occurs in a transform @@ -140,7 +145,7 @@ def report_error(err): echo_file.write(line.encode('ASCII', 'replace')) num_errors = num_errors + 1 if Options.fatal_errors: - raise InternalError, "abort" + raise AbortError, "fatal errors" def error(position, message): #print "Errors.error:", repr(position), repr(message) ### diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 2c46202e..e9f80b2d 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -19,7 +19,7 @@ import Errors import Parsing import Version from Scanning import PyrexScanner, FileSourceDescriptor -from Errors import PyrexError, CompileError, InternalError, error, warning +from Errors import PyrexError, CompileError, InternalError, AbortError, error, warning from Symtab import BuiltinScope, ModuleScope from Cython import Utils from Cython.Utils import open_new_file, replace_suffix @@ -38,7 +38,7 @@ def dumptree(t): def abort_on_errors(node): # Stop the pipeline if there are any errors. if Errors.num_errors != 0: - raise InternalError, "abort" + raise AbortError, "pipeline break" return node class CompilationData(object): @@ -218,23 +218,26 @@ class Context(object): error = None data = source try: - for phase in pipeline: - if phase is not None: - if DebugFlags.debug_verbose_pipeline: - t = time() - print "Entering pipeline phase %r" % phase - data = phase(data) - if DebugFlags.debug_verbose_pipeline: - print " %.3f seconds" % (time() - t) - except CompileError, err: - # err is set - Errors.report_error(err) - error = err + try: + for phase in pipeline: + if phase is not None: + if DebugFlags.debug_verbose_pipeline: + t = time() + print "Entering pipeline phase %r" % phase + data = phase(data) + if DebugFlags.debug_verbose_pipeline: + print " %.3f seconds" % (time() - t) + except CompileError, err: + # err is set + Errors.report_error(err) + error = err except InternalError, err: # Only raise if there was not an earlier error if Errors.num_errors == 0: raise error = err + except AbortError, err: + error = err return (error, data) def find_module(self, module_name, diff --git a/Cython/Compiler/Visitor.py b/Cython/Compiler/Visitor.py index dddef04e..65220b7e 100644 --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@ -173,6 +173,8 @@ class TreeVisitor(object): result = handler_method(child) except Errors.CompileError: raise + except Errors.AbortError: + raise except Exception, e: if DebugFlags.debug_no_exception_intercept: raise