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): ...@@ -97,6 +97,7 @@ class RpcResult(object):
self.offline = offline self.offline = offline
self.call = call self.call = call
self.node = node self.node = node
if offline: if offline:
self.fail_msg = "Node is marked offline" self.fail_msg = "Node is marked offline"
self.data = self.payload = None self.data = self.payload = None
...@@ -108,16 +109,26 @@ class RpcResult(object): ...@@ -108,16 +109,26 @@ class RpcResult(object):
if not isinstance(self.data, (tuple, list)): if not isinstance(self.data, (tuple, list)):
self.fail_msg = ("RPC layer error: invalid result type (%s)" % self.fail_msg = ("RPC layer error: invalid result type (%s)" %
type(self.data)) type(self.data))
self.payload = None
elif len(data) != 2: elif len(data) != 2:
self.fail_msg = ("RPC layer error: invalid result length (%d), " self.fail_msg = ("RPC layer error: invalid result length (%d), "
"expected 2" % len(self.data)) "expected 2" % len(self.data))
self.payload = None
elif not self.data[0]: elif not self.data[0]:
self.fail_msg = self._EnsureErr(self.data[1]) self.fail_msg = self._EnsureErr(self.data[1])
self.payload = None
else: else:
# finally success # finally success
self.fail_msg = None self.fail_msg = None
self.payload = data[1] 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 @staticmethod
def _EnsureErr(val): def _EnsureErr(val):
"""Helper to ensure we return a 'True' value for error.""" """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