From 032e996aa3ba22d72db30c59598d0734322bee29 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Thu, 21 Jan 2021 14:14:15 +0530 Subject: [PATCH] Handle unknown exceptions in matrix bot --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8d8f582..a2e84ba 100644 --- a/main.py +++ b/main.py @@ -229,7 +229,9 @@ class DiscordClient(discord.ext.commands.Bot): config["homeserver"], config["username"] ) - self.bg_task = self.loop.create_task(self.matrix_client.start(self)) + self.bg_task = self.loop.create_task( + self.log_exceptions(self.matrix_client) + ) self.add_cogs() @@ -244,6 +246,14 @@ class DiscordClient(discord.ext.commands.Bot): or str(channel_id) not in config["bridge"].keys(): return True + async def log_exceptions(self, matrix_client): + try: + return await matrix_client.start(self) + except Exception as e: + matrix_client.logger.warning(f"Unknown exception occurred: {e}") + + await matrix_client.close() + async def on_ready(self): for channel in config["bridge"].keys(): channel_store[channel] = self.get_channel(int(channel))