Commit 6d40690c authored by Guido van Rossum's avatar Guido van Rossum

send_reply(): catch errors in encode() and send a ZRPCError exception

instead.

return_error(): be more careful calling repr() on err_value.
parent aab687e8
...@@ -263,7 +263,15 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -263,7 +263,15 @@ class Connection(smac.SizedMessageAsyncConnection):
return hasattr(self.obj, name) return hasattr(self.obj, name)
def send_reply(self, msgid, ret): def send_reply(self, msgid, ret):
msg = self.marshal.encode(msgid, 0, REPLY, ret) try:
msg = self.marshal.encode(msgid, 0, REPLY, ret)
except self.marshal.errors:
try:
r = repr(ret)
except:
r = "<unreprable>"
err = ZRPCError("Couldn't pickle return %.100s" % r)
msg = self.marshal.encode(msgid, 0, REPLY, (ZRPCError, err))
self.message_output(msg) self.message_output(msg)
self.poll() self.poll()
...@@ -280,7 +288,11 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -280,7 +288,11 @@ class Connection(smac.SizedMessageAsyncConnection):
try: try:
msg = self.marshal.encode(msgid, 0, REPLY, (err_type, err_value)) msg = self.marshal.encode(msgid, 0, REPLY, (err_type, err_value))
except self.marshal.errors: except self.marshal.errors:
err = ZRPCError("Couldn't pickle error %s" % `err_value`) try:
r = repr(err_value)
except:
r = "<unreprable>"
err = ZRPCError("Couldn't pickle error %.100s" % r)
msg = self.marshal.encode(msgid, 0, REPLY, (ZRPCError, err)) msg = self.marshal.encode(msgid, 0, REPLY, (ZRPCError, err))
self.message_output(msg) self.message_output(msg)
self.poll() self.poll()
......
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