branhoff / hooter-the-tutor

0 stars 2 forks source link

Implement proper error handling within each cog #17

Open branhoff opened 1 month ago

branhoff commented 1 month ago

Description

Currently, our cogs lack comprehensive error handling, which can lead to unexpected behavior and poor user experience when errors occur.

Objectives

  1. Implement global error handlers for each cog
  2. Add specific error handling for individual commands
  3. Improve logging for error tracking and debugging
  4. Provide user-friendly error messages

Tasks

Implementation Details

Global Error Handler

For each cog, implement a cog_command_error method:

async def cog_command_error(self, ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        await ctx.send(f"This command is on cooldown. Try again in {error.retry_after:.2f} seconds.")
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f"Missing required argument: {error.param}")
    else:
        await ctx.send("An error occurred while processing the command.")

    logging.error(f"An error occurred in {ctx.command}: {str(error)}")

Specific Command Error Handling

For individual commands that may raise specific exceptions:

@commands.command()
async def example_command(self, ctx):
    try:
        # Command logic here
        result = await self.some_operation()
    except SomeSpecificError as e:
        await ctx.send(f"A specific error occurred: {str(e)}")
        logging.error(f"SomeSpecificError in example_command: {str(e)}")
    except Exception as e:
        await ctx.send("An unexpected error occurred.")
        logging.exception(f"Unexpected error in example_command: {str(e)}")

Acceptance Criteria

Additional Considerations

Resources