Passed
Push — main ( 66ff12...0b8b26 )
by
unknown
01:27
created

pincer.exceptions.InvalidTokenError.__init__()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from typing import Optional
5
6
7
class PincerError(Exception):
8
    """Base exception class for all Pincer errors."""
9
10
11
class UnhandledException(PincerError):
12
    """
13
    Exception which gets thrown if an exception wasn't handled.
14
15
    Please create an issue on our github
16
    if this exception gets thrown.
17
    """
18
19
    def __init__(self, specific: str):
20
        super(UnhandledException, self).__init__(
21
            specific + " Please report this to the library devs."
22
        )
23
24
25
class NoExportMethod(PincerError):
26
    """
27
    Exception which gets raised when an `export` method is expected but not
28
    found in a module.
29
    """
30
31
32
class CommandError(PincerError):
33
    """
34
    Base class for exceptions which are related to commands.
35
    """
36
37
38
class CommandCooldownError(CommandError):
39
    """
40
    Exception which gets raised when a command cooldown has not been
41
    breached.
42
    """
43
44
    def __init__(self, message: str, context):
45
        self.ctx = context
46
        super(CommandCooldownError, self).__init__(message)
47
48
49
class CommandIsNotCoroutine(CommandError):
50
    """
51
    Exception raised when the provided command call is not a coroutine.
52
    """
53
54
55
class CommandAlreadyRegistered(CommandError):
56
    """
57
    The command which you are trying to register is already registered.
58
    """
59
60
61
class CommandDescriptionTooLong(CommandError):
62
    """
63
    The provided command description is too long, as it exceeds 100 characters.
64
    """
65
66
67
class TooManyArguments(CommandError):
68
    """
69
    A command can have a maximum of 25 arguments.
70
    If this number of arguments gets exceeded, this exception will be raised.
71
    """
72
73
74
class InvalidArgumentAnnotation(CommandError):
75
    """
76
    The provided argument annotation is not known, so it cannot be used.
77
    """
78
79
80
class CommandReturnIsEmpty(CommandError):
81
    """
82
    Cannot return an empty string to an interaction.
83
    """
84
85
86
class InvalidCommandGuild(CommandError):
87
    """
88
    The provided guild id not not valid.
89
    """
90
91
92
class InvalidCommandName(PincerError):
93
    """
94
    Exception raised when the command is considered invalid.
95
    This is caused by a name that doesn't match the command name regex.
96
    """
97
98
99
class InvalidEventName(PincerError):
100
    """
101
    Exception raised when the event name is not a valid event.
102
    This can be because the event name did not begin with an ``on_`` or
103
    because its not a valid event in the library.
104
    """
105
106
107
class InvalidUrlError(PincerError, ValueError):
108
    """
109
    Exception raised when an invalid url has been provided.
110
    """
111
112
113
class EmbedFieldError(PincerError, ValueError):
114
    """Exception that is raised when an embed field is too large"""
115
116
    @classmethod
117
    def from_desc(cls, _type: str, max_size: int, cur_size: int):
118
        """
119
        Create an instance by description.
120
121
        :param _type:
122
            The type/name of the field.
123
124
        :param max_size:
125
            The maximum size of the field.
126
127
        :param cur_size:
128
            The current size of the field.
129
        """
130
        return cls(
131
            f"{_type} can have a maximum length of {max_size}."
132
            f" (Current size: {cur_size})"
133
        )
134
135
136
class DispatchError(PincerError):
137
    """
138
    Base exception class for all errors which are specifically related
139
    to the dispatcher.
140
    """
141
142
143
class _InternalPerformReconnectError(DispatchError):
144
    """Internal helper exception which on raise lets the client reconnect."""
145
146
147
class DisallowedIntentsError(DispatchError):
148
    """
149
    Invalid gateway intent got provided.
150
    Make sure your client has the enabled intent.
151
    """
152
153
154
class InvalidTokenError(DispatchError, ValueError):
155
    """
156
    Exception raised when the authorization token is invalid.
157
    """
158
159
    def __init__(self, hint: Optional[str] = None):
160
        """
161
        :param hint:
162
            Additional information about the exception cause.
163
        """
164
        hint = hint or ''
165
166
        super(InvalidTokenError, self).__init__(
167
            "The given token is not a valid token.\n" + hint
168
        )
169
170
171
class HeartbeatError(DispatchError):
172
    """Exception raised due to a problem with websocket heartbeat."""
173
174
175
class UnavailableGuildError(PincerError):
176
    """
177
    Exception raised due to a guild being unavailable.
178
    This is caused by a discord outage.
179
    """
180
181
182
# Discord HTTP Errors
183
# `developers/docs/topics/opcodes-and-status-codes#http`
184
185
186
class HTTPError(PincerError):
187
    """HTTP Exception base class."""
188
189
190
class NotModifiedError(HTTPError):
191
    """Error code 304."""
192
193
194
class BadRequestError(HTTPError):
195
    """Error code 400."""
196
197
198
class UnauthorizedError(HTTPError):
199
    """Error code 401."""
200
201
202
class ForbiddenError(HTTPError):
203
    """Error code 403."""
204
205
206
class NotFoundError(HTTPError):
207
    """Error code 404."""
208
209
210
class MethodNotAllowedError(HTTPError):
211
    """Error code 405."""
212
213
214
class RateLimitError(HTTPError):
215
    """Error code 429."""
216
217
218
class GatewayError(HTTPError):
219
    """Error code 502."""
220
221
222
class ServerError(HTTPError):
223
    """
224
    Error code 5xx.
225
    Status code is not in the discord API
226
    """
227