Commits

Ronan Lamy  committed 7c12d65

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.

  • Participants
  • Parent commits fa57953
  • Branches translation-cleanup

Comments (0)

Files changed (2)

File pypy/objspace/flow/flowcontext.py

 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
                 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):

File pypy/objspace/flow/objspace.py

         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)
                 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):