Commit 1645d22d authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Ensure RpcResult has “payload” attribute



Also add assertions to avoid missing attributes in the future.
They won't be included in optimized bytecode.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent aeaa2ea2
......@@ -97,6 +97,7 @@ class RpcResult(object):
self.offline = offline
self.call = call
self.node = node
if offline:
self.fail_msg = "Node is marked offline"
self.data = self.payload = None
......@@ -108,16 +109,26 @@ class RpcResult(object):
if not isinstance(self.data, (tuple, list)):
self.fail_msg = ("RPC layer error: invalid result type (%s)" %
type(self.data))
self.payload = None
elif len(data) != 2:
self.fail_msg = ("RPC layer error: invalid result length (%d), "
"expected 2" % len(self.data))
self.payload = None
elif not self.data[0]:
self.fail_msg = self._EnsureErr(self.data[1])
self.payload = None
else:
# finally success
self.fail_msg = None
self.payload = data[1]
assert hasattr(self, "call")
assert hasattr(self, "data")
assert hasattr(self, "fail_msg")
assert hasattr(self, "node")
assert hasattr(self, "offline")
assert hasattr(self, "payload")
@staticmethod
def _EnsureErr(val):
"""Helper to ensure we return a 'True' value for error."""
......
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