Skip to content

Commit c10027c

Browse files
committed
Move exceptions to dedicated file
1 parent c91334b commit c10027c

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

bot/src/ghutils/cogs/app_commands/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
from ghutils.common.__version__ import VERSION
2222
from ghutils.core.cog import GHUtilsCog, SubGroup
23-
from ghutils.core.types import InvalidInputError, LoginState, NotLoggedInError
23+
from ghutils.core.exceptions import InvalidInputError, NotLoggedInError
24+
from ghutils.core.types import LoginState
2425
from ghutils.db.models import (
2526
UserGitHubTokens,
2627
UserLogin,

bot/src/ghutils/core/exceptions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Any
2+
3+
from discord.app_commands import AppCommandError
4+
5+
6+
# TODO: add Literal[LoginState.LOGGED_OUT, LoginState.EXPIRED] parameter
7+
class NotLoggedInError(AppCommandError):
8+
"""An exception raised when the command user is not logged in to GitHub.
9+
10+
Commands that require the user of the command to log in with GitHub can throw this
11+
if the user is not logged in to reply with a standard error message.
12+
"""
13+
14+
15+
class SilentError(AppCommandError):
16+
"""Base class for exceptions that should be silently caught and ignored."""
17+
18+
19+
class InvalidInputError(AppCommandError):
20+
"""An exception raised within command handlers when an input value is invalid.
21+
22+
Displays a similar error message as `TransformerError`.
23+
"""
24+
25+
def __init__(self, value: Any, message: str):
26+
self.value = value
27+
self.message = message
28+
super().__init__(f"{message} (value: {value})")

bot/src/ghutils/core/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
TransformerError,
1111
)
1212

13-
from .types import InvalidInputError, NotLoggedInError, SilentError
13+
from .exceptions import InvalidInputError, NotLoggedInError, SilentError
1414

1515

1616
class GHUtilsCommandTree(CommandTree):

bot/src/ghutils/core/types.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
11
from enum import Enum, auto
2-
from typing import Any
3-
4-
from discord.app_commands import AppCommandError
52

63

74
class LoginState(Enum):
85
LOGGED_IN = auto()
96
LOGGED_OUT = auto()
107
EXPIRED = auto()
11-
12-
13-
# TODO: add Literal[LoginState.LOGGED_OUT, LoginState.EXPIRED] parameter
14-
class NotLoggedInError(AppCommandError):
15-
"""An exception raised when the command user is not logged in to GitHub.
16-
17-
Commands that require the user of the command to log in with GitHub can throw this
18-
if the user is not logged in to reply with a standard error message.
19-
"""
20-
21-
22-
class SilentError(AppCommandError):
23-
"""Base class for exceptions that should be silently caught and ignored."""
24-
25-
26-
class InvalidInputError(AppCommandError):
27-
"""An exception raised within command handlers when an input value is invalid.
28-
29-
Displays a similar error message as `TransformerError`.
30-
"""
31-
32-
def __init__(self, value: Any, message: str):
33-
self.value = value
34-
self.message = message
35-
super().__init__(f"{message} (value: {value})")

0 commit comments

Comments
 (0)