From 9f6cc2968f1304084209c4e796ab933aa4edb90f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 4 Oct 2023 09:29:49 -0400 Subject: [PATCH] fix(moderation): added proper error handling to cog_load and db_generate_guild_join --- moderation/moderation.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 1ba0a79..142dea7 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -22,6 +22,15 @@ class Moderation(commands.Cog): async def cog_load(self): """This method prepares the database schema for all of the guilds the bot is currently in.""" + conf = await self.check_conf([ + 'mysql_address', + 'mysql_database', + 'mysql_user', + 'mysql_password' + ]) + if conf: + logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.") + return guilds: list[discord.Guild] = self.bot.guilds for guild in guilds: await self.create_guild_table(guild) @@ -29,6 +38,15 @@ class Moderation(commands.Cog): @commands.Cog.listener('on_guild_join') async def db_generate_guild_join(self, guild: discord.Guild): """This method prepares the database schema whenever the bot joins a guild.""" + conf = await self.check_conf([ + 'mysql_address', + 'mysql_database', + 'mysql_user', + 'mysql_password' + ]) + if conf: + logging.fatal("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id) + return await self.create_guild_table(guild) async def connect(self): @@ -40,7 +58,7 @@ class Moderation(commands.Cog): 'mysql_password' ]) if conf: - raise LookupError + raise LookupError("MySQL connection details not set properly!") try: connection = mysql.connector.connect( host=await self.config.mysql_address(),