From 69a338f61065e765b3f062fdc7bb2facf4ebda42 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 4 Jan 2021 08:29:59 -0400 Subject: [PATCH] Fix handling errors in config files on startup --- src/backend/user_files.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backend/user_files.py b/src/backend/user_files.py index fd6cb4fb..29d8f392 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -48,12 +48,15 @@ class UserFile: _writer: Optional[asyncio.Future] = field(init=False, default=None) def __post_init__(self) -> None: + self.data = self.default_data + self._need_write = self.create_missing + if self.path.exists(): - text = self.path.read_text() - self.data, self._need_write = self.deserialized(text) - else: - self.data = self.default_data - self._need_write = self.create_missing + try: + text = self.path.read_text() + self.data, self._need_write = self.deserialized(text) + except Exception as err: # noqa + LoopException(str(err), err, traceback.format_exc().rstrip()) self._reader = asyncio.ensure_future(self._start_reader()) self._writer = asyncio.ensure_future(self._start_writer()) @@ -414,7 +417,9 @@ class Settings(ConfigFile, PCNFile): section, save = super().deserialized(data) if self and self.General.theme != section.General.theme: - self.backend.theme.stop_watching() + if hasattr(self.backend, "theme"): + self.backend.theme.stop_watching() + self.backend.theme = Theme( self.backend, section.General.theme, # type: ignore )