commit 9bd082cd825e3bbffe146cbf6534e6e7c1e7c1f0
parent 46fcf686b1ec8603d240b718a644d9e188ca9f1a
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 29 May 2018 13:37:30 +0200
trezor/keepkey: better handling of exceptions during device initialization
notably Trezor T is returning a different msg type when trying to get an xpub from an uninitialized device, which we are not handling. instead we should just realise ourselves that we did not initialize the device
Diffstat:
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/plugins/keepkey/keepkey.py b/plugins/keepkey/keepkey.py
@@ -181,19 +181,26 @@ class KeepKeyPlugin(HW_PluginBase):
t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler))
t.setDaemon(True)
t.start()
- wizard.loop.exec_()
+ exit_code = wizard.loop.exec_()
+ if exit_code != 0:
+ # this method (initialize_device) was called with the expectation
+ # of leaving the device in an initialized state when finishing.
+ # signal that this is not the case:
+ raise UserCancelled()
wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f)
def _initialize_device_safe(self, settings, method, device_id, wizard, handler):
+ exit_code = 0
try:
self._initialize_device(settings, method, device_id, wizard, handler)
except UserCancelled:
- pass
+ exit_code = 1
except BaseException as e:
traceback.print_exc(file=sys.stderr)
handler.show_error(str(e))
+ exit_code = 1
finally:
- wizard.loop.exit(0)
+ wizard.loop.exit(exit_code)
def _initialize_device(self, settings, method, device_id, wizard, handler):
item, label, pin_protection, passphrase_protection = settings
diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py
@@ -202,19 +202,26 @@ class TrezorPlugin(HW_PluginBase):
t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler))
t.setDaemon(True)
t.start()
- wizard.loop.exec_()
+ exit_code = wizard.loop.exec_()
+ if exit_code != 0:
+ # this method (initialize_device) was called with the expectation
+ # of leaving the device in an initialized state when finishing.
+ # signal that this is not the case:
+ raise UserCancelled()
wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f)
def _initialize_device_safe(self, settings, method, device_id, wizard, handler):
+ exit_code = 0
try:
self._initialize_device(settings, method, device_id, wizard, handler)
except UserCancelled:
- pass
+ exit_code = 1
except BaseException as e:
traceback.print_exc(file=sys.stderr)
handler.show_error(str(e))
+ exit_code = 1
finally:
- wizard.loop.exit(0)
+ wizard.loop.exit(exit_code)
def _initialize_device(self, settings, method, device_id, wizard, handler):
item, label, pin_protection, passphrase_protection, recovery_type = settings