Commit 75c3536e authored by Robert Bradshaw's avatar Robert Bradshaw

Fix fatal errors + nice exception traceback interaction.

parent c6ecb09c
...@@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning): ...@@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning):
# self.message = message # self.message = message
Exception.__init__(self, format_position(position) + message) Exception.__init__(self, format_position(position) + message)
class InternalError(Exception): class InternalError(Exception):
# If this is ever raised, there is a bug in the compiler. # If this is ever raised, there is a bug in the compiler.
...@@ -70,6 +69,12 @@ class InternalError(Exception): ...@@ -70,6 +69,12 @@ class InternalError(Exception):
Exception.__init__(self, u"Internal compiler error: %s" Exception.__init__(self, u"Internal compiler error: %s"
% message) % 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): class CompilerCrash(CompileError):
# raised when an unexpected exception occurs in a transform # raised when an unexpected exception occurs in a transform
...@@ -140,7 +145,7 @@ def report_error(err): ...@@ -140,7 +145,7 @@ def report_error(err):
echo_file.write(line.encode('ASCII', 'replace')) echo_file.write(line.encode('ASCII', 'replace'))
num_errors = num_errors + 1 num_errors = num_errors + 1
if Options.fatal_errors: if Options.fatal_errors:
raise InternalError, "abort" raise AbortError, "fatal errors"
def error(position, message): def error(position, message):
#print "Errors.error:", repr(position), repr(message) ### #print "Errors.error:", repr(position), repr(message) ###
......
...@@ -19,7 +19,7 @@ import Errors ...@@ -19,7 +19,7 @@ import Errors
import Parsing import Parsing
import Version import Version
from Scanning import PyrexScanner, FileSourceDescriptor 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 Symtab import BuiltinScope, ModuleScope
from Cython import Utils from Cython import Utils
from Cython.Utils import open_new_file, replace_suffix from Cython.Utils import open_new_file, replace_suffix
...@@ -38,7 +38,7 @@ def dumptree(t): ...@@ -38,7 +38,7 @@ def dumptree(t):
def abort_on_errors(node): def abort_on_errors(node):
# Stop the pipeline if there are any errors. # Stop the pipeline if there are any errors.
if Errors.num_errors != 0: if Errors.num_errors != 0:
raise InternalError, "abort" raise AbortError, "pipeline break"
return node return node
class CompilationData(object): class CompilationData(object):
...@@ -218,23 +218,26 @@ class Context(object): ...@@ -218,23 +218,26 @@ class Context(object):
error = None error = None
data = source data = source
try: try:
for phase in pipeline: try:
if phase is not None: for phase in pipeline:
if DebugFlags.debug_verbose_pipeline: if phase is not None:
t = time() if DebugFlags.debug_verbose_pipeline:
print "Entering pipeline phase %r" % phase t = time()
data = phase(data) print "Entering pipeline phase %r" % phase
if DebugFlags.debug_verbose_pipeline: data = phase(data)
print " %.3f seconds" % (time() - t) if DebugFlags.debug_verbose_pipeline:
except CompileError, err: print " %.3f seconds" % (time() - t)
# err is set except CompileError, err:
Errors.report_error(err) # err is set
error = err Errors.report_error(err)
error = err
except InternalError, err: except InternalError, err:
# Only raise if there was not an earlier error # Only raise if there was not an earlier error
if Errors.num_errors == 0: if Errors.num_errors == 0:
raise raise
error = err error = err
except AbortError, err:
error = err
return (error, data) return (error, data)
def find_module(self, module_name, def find_module(self, module_name,
......
...@@ -173,6 +173,8 @@ class TreeVisitor(object): ...@@ -173,6 +173,8 @@ class TreeVisitor(object):
result = handler_method(child) result = handler_method(child)
except Errors.CompileError: except Errors.CompileError:
raise raise
except Errors.AbortError:
raise
except Exception, e: except Exception, e:
if DebugFlags.debug_no_exception_intercept: if DebugFlags.debug_no_exception_intercept:
raise raise
......
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