[pypy-commit] pypy translation-cleanup: Implement exception formatting inside FlowingError

rlamy noreply at buildbot.pypy.org
Thu Sep 20 19:39:22 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57436:7c12d65a06e3
Date: 2012-09-20 02:45 +0100
http://bitbucket.org/pypy/pypy/changeset/7c12d65a06e3/

Log:	Implement exception formatting inside FlowingError

	This avoids unnecessary catching/munging/reraising of exceptions.

	+ Attach the FlowSpaceFrame to the exception, allowing improved
	debugging and advanced error-handling. + Fix crazy hack for
	undefined globals.

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -16,15 +16,22 @@
 from pypy.objspace.flow.bytecode import HostCode
 
 class FlowingError(Exception):
-    pass
+    """ Signals invalid RPython in the function being analysed"""
+    def __init__(self, frame, msg):
+        super(FlowingError, self).__init__(msg)
+        self.frame = frame
+
+    def __str__(self):
+        return format_global_error(self.frame.graph, self.frame.last_instr,
+                str(self.msg))
+
 
 class StopFlowing(Exception):
     pass
 
 class FSException(OperationError):
     def __init__(self, w_type, w_value, tb=None):
-        if w_type is None:
-            raise FlowingError(w_value)
+        assert w_type is not None
         self.w_type = w_type
         self.w_value = w_value
         self._application_traceback = tb
@@ -425,13 +432,6 @@
                 link = Link([w_result], self.graph.returnblock)
                 self.recorder.crnt_block.closeblock(link)
 
-            except FlowingError, a:
-                # attach additional source info to AnnotatorError
-                _, _, tb = sys.exc_info()
-                formatted = format_global_error(self.graph, self.last_instr,
-                                                    str(a))
-                e = FlowingError(formatted)
-                raise FlowingError, e, tb
         del self.recorder
 
     def mergeblock(self, currentblock, currentstate):
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -190,8 +190,8 @@
         except UnwrapException:
             raise Exception, "non-constant except guard"
         if check_class in (NotImplementedError, AssertionError):
-            raise FlowingError("Catching %s is not valid in RPython" %
-                                     check_class.__name__)
+            raise FlowingError(self.frame,
+                "Catching %s is not valid in RPython" % check_class.__name__)
         if not isinstance(check_class, tuple):
             # the simple case
             return ObjSpace.exception_match(self, w_exc_type, w_check_class)
@@ -421,7 +421,7 @@
                 value = getattr(self.unwrap(self.builtin), varname)
             except AttributeError:
                 message = "global name '%s' is not defined" % varname
-                raise FSException(self.w_NameError, self.wrap(message))
+                raise FlowingError(self.frame, self.wrap(message))
         return self.wrap(value)
 
     def w_KeyboardInterrupt(self):


More information about the pypy-commit mailing list