[Twisted-Python] Transforming Exception -> pb.Error in a remote_foo method

Brian Granger ellisonbg.net at gmail.com
Wed Dec 20 12:17:04 EST 2006


In the Twisted docs it is claimed that in order to propagate exceptions over PB:

"The only special thing you do is to define your Exception subclass by
deriving it from pb.Error. "

This seems simple enough, but I am using PB to adapt a general service
that doesn't use pb.Errors (as the service is also adapted to other
protocols).  How can one transform a regular Exception to a pb.Error?
The following does not work:

    def remote_foo(self, f):
        d = self.service.foo(f)
        def raiser():
            raise pb.Error('I pbfailed')
        d.addErrback(lambda reason: raiser())        # reason is an
Exception, not a pb.Error!
        return d

In this case, the server still complains about an unhandled exception.

Any thoughts about how to do this?



More information about the Twisted-Python mailing list