qt gui: more resilient startup: catch more exceptions, better fallback
fixes https://github.com/spesmilo/electrum/issues/7447 Consider this trace for 4.2.0: ``` Traceback (most recent call last): File "electrum/gui/qt/__init__.py", line 332, in start_new_window File "electrum/gui/qt/__init__.py", line 363, in _start_wizard_to_select_or_create_wallet File "electrum/gui/qt/installwizard.py", line 302, in select_storage File "electrum/util.py", line 504, in get_new_wallet_name PermissionError: [Errno 1] Operation not permitted: '/Users/admin/Documents/Peach/MS' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "electrum/gui/qt/__init__.py", line 426, in main File "electrum/gui/qt/__init__.py", line 307, in wrapper File "electrum/gui/qt/__init__.py", line 349, in start_new_window File "electrum/util.py", line 504, in get_new_wallet_name PermissionError: [Errno 1] Operation not permitted: '/Users/admin/Documents/Peach/MS' ``` Note that `get_new_wallet_name` (os.listdir) can raise OSError, and we were calling that on the main entrypoint codepath without exception-handling. We were also calling it in the fallback codepath without exception-handling. i.e. the GUI errored out on every startup for affected users, and without CLI usage it was not possible to recover.
This commit is contained in:
@@ -296,12 +296,7 @@ class SimpleConfig(Logger):
|
||||
if path and os.path.exists(path):
|
||||
return path
|
||||
|
||||
# default path
|
||||
util.assert_datadir_available(self.path)
|
||||
dirpath = os.path.join(self.path, "wallets")
|
||||
make_dir(dirpath, allow_symlink=False)
|
||||
|
||||
new_path = os.path.join(self.path, "wallets", "default_wallet")
|
||||
new_path = self.get_fallback_wallet_path()
|
||||
|
||||
# default path in pre 1.9 versions
|
||||
old_path = os.path.join(self.path, "electrum.dat")
|
||||
@@ -310,6 +305,13 @@ class SimpleConfig(Logger):
|
||||
|
||||
return new_path
|
||||
|
||||
def get_fallback_wallet_path(self):
|
||||
util.assert_datadir_available(self.path)
|
||||
dirpath = os.path.join(self.path, "wallets")
|
||||
make_dir(dirpath, allow_symlink=False)
|
||||
path = os.path.join(self.path, "wallets", "default_wallet")
|
||||
return path
|
||||
|
||||
def remove_from_recently_open(self, filename):
|
||||
recent = self.get('recently_open', [])
|
||||
if filename in recent:
|
||||
|
||||
Reference in New Issue
Block a user