-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use botcore command error manager #1458
Conversation
fd6490c
to
9d330d0
Compare
9d330d0
to
832acb1
Compare
I'll squash the implementation commits along with the fixup one once the PR is ready to be merged. |
832acb1
to
5c610e0
Compare
5c610e0
to
6f8a5b1
Compare
Honestly, I don't understand the benefit of this error dispatching system. I feel like this introduces extra complexity and makes the logic much harder to follow and understand. Before, following the logic was as simple as:
Now, to follow the logic it's:
I'm not sure what benefit these extra steps have given us over the current code. |
The idea initially came to make the exception handling logic reusable for both prefix command & slash command errors. For context, we have some prefix/text commands that also have their slash version sibling, and these commands use the same logic/throw the same errors. The question was (and I'd be interested to have your point of view), how do we reuse all the logic that existed in the error handling cog in case we have errors that came from these slash commands ? Discord py dispatches these prefix commands through the I just thought of unifying both under the same interface and hiding the conversion details for the same type of error. I understand your point of view and agree that it's slightly more complex than the setup we currently have but I don't necessarily agree that it's makes it much harder to follow nor that complex, but that could just be the fact that I'm biased since I'm the one who wrote, which makes the understanding easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few preliminary comments - still need to do a deeper review.
"""A predicate that determines whether the error should be handled or not.""" | ||
return isinstance(error, CheckFailure) | ||
|
||
async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of a function is None
. If a function can return, but has no explicit return value, then this annotation should be None
.
NoReturn
means it does not return i.e. control flow of the program is interrupted before it returns. I've only seen this used for functions that always throw an exception, like an abstract method that raises NotImplemented. Also, this was superceded (?) in 3.11 by Never
.
def __init__(self, bot: Bot): | ||
self.bot = bot | ||
|
||
async def should_handle_error(self, error: errors.DiscordException) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts about using @typing.override
for these? It makes it more explicit that this is an override, and it helps type checkers. But if we don't use a type checker then it could be argued that this would just clutter the code.
Closing this as we haven't reached a consensus within the core dev team. |
This deflates the
CommandErrorHandler
from all the conditionals in place when it comes to error types.Most importantly, it allows us to centralize error handling of both
text
andslash
commands in one place, and reuse any necessary logic.