Fix longstanding crash when prefs.yaml is corrupted

Instead, warn the user with a popup dialog, and reset settings to
default.

Every few months, a user would report corrscope failing to open
due to a corrupted prefs.yaml.
This commit should stop all occurrences of that from now on.
The next commit will help ensure that we never save corrupted files
in the first place.
pull/377/head
nyanpasu64 2021-06-13 20:37:24 -07:00
rodzic f80730ffd7
commit 9b97221001
1 zmienionych plików z 14 dodań i 1 usunięć

Wyświetl plik

@ -175,7 +175,14 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
super().__init__()
# Load settings.
self.pref = gp.load_prefs()
prefs_error = None
try:
self.pref = gp.load_prefs()
if not isinstance(self.pref, gp.GlobalPrefs):
raise TypeError(f"prefs.yaml contains wrong type {type(self.pref)}")
except Exception as e:
prefs_error = e
self.pref = gp.GlobalPrefs()
# Load UI.
self.setupUi(self) # sets windowTitle
@ -237,6 +244,12 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
self.show()
if prefs_error is not None:
TracebackDialog(self).showMessage(
"Warning: failed to load global preferences, resetting to default.\n"
+ format_stack_trace(prefs_error)
)
_cfg_path: Optional[Path]
# Whether document is dirty, changed, has unsaved changes