pcparadise / discordbot

GNU General Public License v3.0
3 stars 5 forks source link

Implement basic error handling framework #49

Closed Ganoodles closed 1 year ago

awsomearvinder commented 1 year ago

Try using a match statement instead of if isinstance. IMO it makes for cleaner code for stuff like this. Also, I'm not too much of a fan of all dynamic behavior of the code as is to be honest. Is there any reason we can't just have:

match error:
    case discord.CommandError if error.message:
        error_embed.add_field("Error", error.message)
     case _:
         error_embed.add_field("Error", "an unknown error has occured")

for the handler?

On another note, errors should probably be defined in like, src/errors.py and not src/utils.

edit: had a talk on discord, exact handler should be something like,

match error:
    case discord.CommandError(message) if message:
        error_embed.add_field("Error", message)
    case _:
        error_embed.add_field("Error", "An unknown error has occurred")
awsomearvinder commented 1 year ago

Reminding myself to close #16 when this is merged

Ganoodles commented 1 year ago

@awsomearvinder, those changes should be implemented. I chose to remove errors.py entirely in favor of using only the default discord error handling; it seemed to be more than sufficient, and I couldn't think of any use cases in which someone would need to add a custom error message. Although, I left the code in there (commented out) just in case someone needs to use it.