diff options
author | 2024-02-01 13:32:09 +0100 | |
---|---|---|
committer | 2024-03-18 11:37:57 +0100 | |
commit | 6553f038c0604febd19230d53cc776077f802102 (patch) | |
tree | e2bf3eee279b26355878bf949a36f540c64f99e4 | |
parent | make error_handling a package (diff) |
add the AbstractCommandErrorHandler interface
this represents an interface that all command handlers will need to implement in order to be able to use them in both app & text command errors
-rw-r--r-- | pydis_core/utils/error_handling/commands/__init__.py | 3 | ||||
-rw-r--r-- | pydis_core/utils/error_handling/commands/abc.py | 24 |
2 files changed, 27 insertions, 0 deletions
diff --git a/pydis_core/utils/error_handling/commands/__init__.py b/pydis_core/utils/error_handling/commands/__init__.py new file mode 100644 index 00000000..2b648c07 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/__init__.py @@ -0,0 +1,3 @@ +from .abc import AbstractCommandErrorHandler + +__all__ = ["AbstractCommandErrorHandler"] diff --git a/pydis_core/utils/error_handling/commands/abc.py b/pydis_core/utils/error_handling/commands/abc.py new file mode 100644 index 00000000..f155b239 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/abc.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod +from typing import NoReturn + +from discord import Interaction +from discord.ext.commands import Context + + +class AbstractCommandErrorHandler(ABC): + """An abstract command error handler.""" + + @abstractmethod + async def should_handle_error(self, error: Exception) -> bool: + """A predicate that determines whether the error should be handled.""" + raise NotImplementedError + + @abstractmethod + async def handle_app_command_error(self, interaction: Interaction, error: Exception) -> NoReturn: + """Handle error raised in the context of app commands.""" + raise NotImplementedError + + @abstractmethod + async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: + """Handle error raised in the context of text commands.""" + raise NotImplementedError |