Show error on startup/sync failure

This commit is contained in:
Andrew Ferrazzutti 2022-03-11 03:40:20 -05:00
parent 66b66bd27b
commit c48952a9fa
2 changed files with 15 additions and 4 deletions

View File

@ -110,5 +110,7 @@ async def refresh(evt: CommandEvent) -> None:
) )
async def sync(evt: CommandEvent) -> None: async def sync(evt: CommandEvent) -> None:
await evt.mark_read() await evt.mark_read()
await evt.sender.post_login(is_startup=False) if await evt.sender.post_login(is_startup=False):
await evt.reply("Sync complete") await evt.reply("Sync complete")
else:
await evt.reply("Sync failed")

View File

@ -71,6 +71,7 @@ BridgeState.human_readable_errors.update(
"kt-reconnection-error": "Failed to reconnect to KakaoTalk", "kt-reconnection-error": "Failed to reconnect to KakaoTalk",
"kt-connection-error": "KakaoTalk disconnected unexpectedly", "kt-connection-error": "KakaoTalk disconnected unexpectedly",
"kt-auth-error": "Authentication error from KakaoTalk: {message}", "kt-auth-error": "Authentication error from KakaoTalk: {message}",
"kt-start-error": "Startup error from KakaoTalk: {message}",
"kt-disconnected": None, "kt-disconnected": None,
"logged-out": "You're not logged into KakaoTalk", "logged-out": "You're not logged into KakaoTalk",
} }
@ -398,7 +399,7 @@ class User(DBUser, BaseUser):
await self.save() await self.save()
return ok 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.log.info("Running post-login actions")
self._add_to_cache() self._add_to_cache()
@ -417,6 +418,7 @@ class User(DBUser, BaseUser):
login_result = await self.client.start() login_result = await self.client.start()
await self._sync_channels(login_result, is_startup) await self._sync_channels(login_result, is_startup)
self.start_listen() self.start_listen()
return True
except AuthenticationRequired as e: except AuthenticationRequired as e:
await self.send_bridge_notice( await self.send_bridge_notice(
f"Got authentication error from KakaoTalk:\n\n> {e.message}\n\n", 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) await self.logout(remove_ktid=False)
except Exception as e: except Exception as e:
self.log.exception("Failed to start client") 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]]: async def get_direct_chats(self) -> dict[UserID, list[RoomID]]:
return { return {