2018-11-08 17:15:49 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-11-08 17:15:49 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
|
2018-09-13 16:47:19 +00:00
|
|
|
class TrezorException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-10-12 13:49:17 +00:00
|
|
|
class TrezorFailure(TrezorException):
|
|
|
|
def __init__(self, failure):
|
|
|
|
self.failure = failure
|
2020-03-24 15:24:53 +00:00
|
|
|
self.code = failure.code
|
|
|
|
self.message = failure.message
|
|
|
|
super().__init__(self.code, self.message, self.failure)
|
2018-10-12 13:49:17 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
from .messages import FailureType
|
|
|
|
|
|
|
|
types = {
|
|
|
|
getattr(FailureType, name): name
|
|
|
|
for name in dir(FailureType)
|
|
|
|
if not name.startswith("_")
|
|
|
|
}
|
2020-03-24 15:24:53 +00:00
|
|
|
if self.message is not None:
|
|
|
|
return "{}: {}".format(types[self.code], self.message)
|
2018-10-12 13:49:17 +00:00
|
|
|
else:
|
|
|
|
return types[self.failure.code]
|
|
|
|
|
|
|
|
|
2018-09-13 16:47:19 +00:00
|
|
|
class PinException(TrezorException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Cancelled(TrezorException):
|
|
|
|
pass
|
2018-12-04 14:42:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OutdatedFirmwareError(TrezorException):
|
|
|
|
pass
|