1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00

CallException has always code and message

This commit is contained in:
slush0 2014-02-09 00:12:22 +01:00
parent f5606d6824
commit 262d493ce2

View File

@ -29,7 +29,9 @@ def word_func():
return raw_input("Enter one word of mnemonic: ") return raw_input("Enter one word of mnemonic: ")
class CallException(Exception): class CallException(Exception):
pass def __init__(self, code, message):
super(CallException, self).__init__()
self.args = [code, message]
class PinException(CallException): class PinException(CallException):
pass pass
@ -166,11 +168,12 @@ class TrezorClient(object):
try: try:
exp = expected_buttonrequests.pop(0) exp = expected_buttonrequests.pop(0)
if resp.code != exp: if resp.code != exp:
raise CallException("Expected %s, got %s" % \ raise CallException(types.Failure_Other, "Expected %s, got %s" % \
(self._get_buttonrequest_value(exp), (self._get_buttonrequest_value(exp),
self._get_buttonrequest_value(resp.code))) self._get_buttonrequest_value(resp.code)))
except IndexError: except IndexError:
raise CallException("Got %s, but no ButtonRequest has been expected" % \ raise CallException(types.Failure_Other,
"Got %s, but no ButtonRequest has been expected" % \
self._get_buttonrequest_value(resp.code)) self._get_buttonrequest_value(resp.code))
print "ButtonRequest code:", self._get_buttonrequest_value(resp.code) print "ButtonRequest code:", self._get_buttonrequest_value(resp.code)
@ -207,12 +210,9 @@ class TrezorClient(object):
if isinstance(resp, proto.Failure): if isinstance(resp, proto.Failure):
self.message_func(resp.message) self.message_func(resp.message)
if resp.code == types.Failure_ActionCancelled: if resp.code in (types.Failure_PinInvalid,
raise CallException("Action cancelled by user")
elif resp.code in (types.Failure_PinInvalid,
types.Failure_PinCancelled, types.Failure_PinExpected): types.Failure_PinCancelled, types.Failure_PinExpected):
raise PinException("PIN is invalid") raise PinException(resp.code, resp.message)
raise CallException(resp.code, resp.message) raise CallException(resp.code, resp.message)
@ -223,7 +223,8 @@ class TrezorClient(object):
raise CallException("Expected %s message, got %s message" % (expected.DESCRIPTOR.name, resp.DESCRIPTOR.name)) raise CallException("Expected %s message, got %s message" % (expected.DESCRIPTOR.name, resp.DESCRIPTOR.name))
if expected_buttonrequests != None and len(expected_buttonrequests): if expected_buttonrequests != None and len(expected_buttonrequests):
raise CallException("Following ButtonRequests were not in use: %s" % \ raise CallException(types.Failure_Other,
"Following ButtonRequests were not in use: %s" % \
[ self._get_buttonrequest_value(x) for x in expected_buttonrequests]) [ self._get_buttonrequest_value(x) for x in expected_buttonrequests])
return resp return resp