Author: Edd Barrett <vex...@gmail.com> Branch: improve-errors-again Changeset: r66413:34e2f4edb458 Date: 2013-08-28 12:43 +0100 http://bitbucket.org/pypy/pypy/changeset/34e2f4edb458/
Log: (Edd, Ronan) Begin refactoring UnionError/AnnotatorError. diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py --- a/rpython/annotator/annrpython.py +++ b/rpython/annotator/annrpython.py @@ -602,6 +602,10 @@ raise BlockedInference(self, op, opindex) try: resultcell = consider_meth(*argcells) + except annmodel.AnnotatorError as e: # note that UnionError is a subclass + graph = self.bookkeeper.position_key[0] + e.source = '\n'.join(source_lines(graph, block, opindex, long=True)) + raise except Exception, e: graph = self.bookkeeper.position_key[0] e.args = e.args + ( diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py --- a/rpython/annotator/model.py +++ b/rpython/annotator/model.py @@ -678,9 +678,19 @@ class AnnotatorError(Exception): - pass + def __init__(self, msg=None): + self.msg = msg + self.source = None -class UnionError(Exception): + def __str__(self): + s = "\n\n%s" % self.msg + if self.source is not None: + s += "\n\n" + s += self.source + + return s + +class UnionError(AnnotatorError): """Signals an suspicious attempt at taking the union of deeply incompatible SomeXxx instances.""" @@ -690,25 +700,16 @@ The msg paramter is appended to a generic message. This can be used to give the user a little more information. """ + s = "" + if msg is not None: + s += "%s\n\n" % msg + s += "Offending annotations:\n" + s += " %s\n %s" % (s_obj1, s_obj2) self.s_obj1 = s_obj1 self.s_obj2 = s_obj2 - self.msg = msg + self.msg = s self.source = None - def __str__(self): - s = "\n\n" - - if self.msg is not None: - s += "%s\n\n" % self.msg - - s += "Offending annotations:\n" - s += "%s\n%s\n\n" % (self.s_obj1, self.s_obj2) - - if self.source is not None: - s += self.source - - return s - def __repr__(self): return str(self) diff --git a/rpython/tool/error.py b/rpython/tool/error.py --- a/rpython/tool/error.py +++ b/rpython/tool/error.py @@ -109,7 +109,6 @@ def format_blocked_annotation_error(annotator, blocked_blocks): text = [] for block, (graph, index) in blocked_blocks.items(): - text.append('\n') text.append("Blocked block -- operation cannot succeed") text.append(gather_error(annotator, graph, block, index)) return '\n'.join(text) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit