From c48952a9fa3f9f29071103fe5755afd839888a04 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 11 Mar 2022 03:40:20 -0500 Subject: [PATCH] Show error on startup/sync failure --- matrix_appservice_kakaotalk/commands/conn.py | 6 ++++-- matrix_appservice_kakaotalk/user.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/matrix_appservice_kakaotalk/commands/conn.py b/matrix_appservice_kakaotalk/commands/conn.py index 12d1d39..6a1336e 100644 --- a/matrix_appservice_kakaotalk/commands/conn.py +++ b/matrix_appservice_kakaotalk/commands/conn.py @@ -110,5 +110,7 @@ async def refresh(evt: CommandEvent) -> None: ) async def sync(evt: CommandEvent) -> None: await evt.mark_read() - await evt.sender.post_login(is_startup=False) - await evt.reply("Sync complete") + if await evt.sender.post_login(is_startup=False): + await evt.reply("Sync complete") + else: + await evt.reply("Sync failed") diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index 40a8e61..2e8fce4 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -71,6 +71,7 @@ BridgeState.human_readable_errors.update( "kt-reconnection-error": "Failed to reconnect to KakaoTalk", "kt-connection-error": "KakaoTalk disconnected unexpectedly", "kt-auth-error": "Authentication error from KakaoTalk: {message}", + "kt-start-error": "Startup error from KakaoTalk: {message}", "kt-disconnected": None, "logged-out": "You're not logged into KakaoTalk", } @@ -398,7 +399,7 @@ class User(DBUser, BaseUser): await self.save() return ok - async def post_login(self, is_startup: bool) -> None: + async def post_login(self, is_startup: bool) -> bool: self.log.info("Running post-login actions") self._add_to_cache() @@ -417,6 +418,7 @@ class User(DBUser, BaseUser): login_result = await self.client.start() await self._sync_channels(login_result, is_startup) self.start_listen() + return True except AuthenticationRequired as e: await self.send_bridge_notice( f"Got authentication error from KakaoTalk:\n\n> {e.message}\n\n", @@ -428,7 +430,14 @@ class User(DBUser, BaseUser): await self.logout(remove_ktid=False) except Exception as e: self.log.exception("Failed to start client") - await self.push_bridge_state(BridgeStateEvent.UNKNOWN_ERROR, message=str(e)) + await self.send_bridge_notice( + f"Got error from KakaoTalk:\n\n> {e!s}\n\n", + important=True, + state_event=BridgeStateEvent.UNKNOWN_ERROR, + error_code="kt-start-error", + error_message=str(e), + ) + return False async def get_direct_chats(self) -> dict[UserID, list[RoomID]]: return {