From 24180fc34630b3021116fda17eba870636c5451f Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 9 Mar 2020 13:08:09 -0400 Subject: [PATCH] GUI-report important errors that occur during sync Important = "isn't a server 5xx error" --- TODO.md | 2 +- src/backend/matrix_client.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 229abcb3..6279f724 100644 --- a/TODO.md +++ b/TODO.md @@ -3,8 +3,8 @@ ## Before release - Fix highlighted account/room in MainPane -- "exception during sync" aren't caught - nio ClientTimeout +- Default theme? - Name - Update docstrings - Update TODO.md diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 2bb6c285..96e0d74a 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -40,7 +40,7 @@ from .media_cache import Media, Thumbnail from .models.items import Event, Member, Room, Upload, UploadStatus from .models.model_store import ModelStore from .nio_callbacks import NioCallbacks -from .pyotherside_events import AlertRequested +from .pyotherside_events import AlertRequested, LoopException if TYPE_CHECKING: from .backend import Backend @@ -207,7 +207,7 @@ class MatrixClient(nio.AsyncClient): async def _start(self) -> None: - """Fetch our user profile and enter the server sync loop.""" + """Fetch our user profile, server config and enter the sync loop.""" def on_profile_response(future) -> None: """Update our model `Account` with the received profile details.""" @@ -263,9 +263,14 @@ class MatrixClient(nio.AsyncClient): ) await self.sync_task break # task cancelled - except Exception: + except Exception as err: trace = traceback.format_exc().rstrip() - log.error("Exception during sync, restart in 2s:\n%s", trace) + + if isinstance(err, MatrixError) and err.http_code >= 500: + log.error("Server failure during sync:\n%s", trace) + else: + LoopException(str(err), err, trace) + await asyncio.sleep(2)