1
|
|
|
# Copyright Pincer 2021-Present |
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 InvalidPayload(PincerError): |
12
|
|
|
"""Exception which gets thrown if an invalid payload has been received. |
13
|
|
|
This means that the data of the payload did not match the expected |
14
|
|
|
format and/or didn't contain the the expected values. |
15
|
|
|
""" |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class UnhandledException(PincerError): |
19
|
|
|
"""Exception which gets thrown if an exception wasn't handled. |
20
|
|
|
|
21
|
|
|
Please create an issue on our github |
22
|
|
|
if this exception gets thrown. |
23
|
|
|
""" |
24
|
|
|
|
25
|
|
|
def __init__(self, specific: str): |
26
|
|
|
super(UnhandledException, self).__init__( |
27
|
|
|
specific + " Please report this to the library devs." |
28
|
|
|
) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class NoExportMethod(PincerError): |
32
|
|
|
"""Exception which gets raised when an `export` method is expected but |
33
|
|
|
not found in a module. |
34
|
|
|
""" |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class CogError(PincerError): |
38
|
|
|
"""Exception base class for errors related to Cogs.""" |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
class CogNotFound(CogError): |
42
|
|
|
"""Exception which gets raised when a cog is trying to be |
43
|
|
|
loaded/unloaded but is nonexistent. |
44
|
|
|
""" |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
class CogAlreadyExists(CogError): |
48
|
|
|
"""Exception which gets raised when a cog is already loaded, but is |
49
|
|
|
trying to be reloaded! |
50
|
|
|
""" |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
class NoValidSetupMethod(CogError): |
54
|
|
|
"""Exception which gets raised when an `setup` function is expected but |
55
|
|
|
none was found! |
56
|
|
|
""" |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class TooManySetupArguments(CogError): |
60
|
|
|
"""Exception which gets raised when too many arguments were requested |
61
|
|
|
in a cog its setup function. |
62
|
|
|
""" |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
class NoCogManagerReturnFound(CogError): |
66
|
|
|
"""Exception which gets raised when no cog return was found from the |
67
|
|
|
setup function. (are you missing a return statement?) |
68
|
|
|
""" |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
class CommandError(PincerError): |
72
|
|
|
"""Base class for exceptions which are related to commands.""" |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
class CommandCooldownError(CommandError): |
76
|
|
|
"""Exception which gets raised when a command cooldown has not been |
77
|
|
|
breached. |
78
|
|
|
|
79
|
|
|
Attributes |
80
|
|
|
---------- |
81
|
|
|
ctx: :class:`~objects.message.context.MessageContext` |
82
|
|
|
The context of the error |
83
|
|
|
""" |
84
|
|
|
|
85
|
|
|
def __init__(self, message: str, context): |
86
|
|
|
self.ctx = context |
87
|
|
|
super(CommandCooldownError, self).__init__(message) |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
class CommandIsNotCoroutine(CommandError): |
91
|
|
|
"""Exception raised when the provided command call is not a coroutine.""" |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
class CommandAlreadyRegistered(CommandError): |
95
|
|
|
"""The command which you are trying to register is already registered.""" |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
class CommandDescriptionTooLong(CommandError): |
99
|
|
|
"""The provided command description is too long, |
100
|
|
|
as it exceeds 100 characters. |
101
|
|
|
""" |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
class TooManyArguments(CommandError): |
105
|
|
|
"""A command can have a maximum of 25 arguments. |
106
|
|
|
If this number of arguments gets exceeded, this exception will be raised. |
107
|
|
|
""" |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
class InvalidArgumentAnnotation(CommandError): |
111
|
|
|
"""The provided argument annotation is not known, so it cannot be used.""" |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
class CommandReturnIsEmpty(CommandError): |
115
|
|
|
"""Cannot return an empty string to an interaction.""" |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
class InvalidCommandGuild(CommandError): |
119
|
|
|
"""The provided guild id not not valid.""" |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
class InvalidCommandName(CommandError): |
123
|
|
|
"""Exception raised when the command is considered invalid. |
124
|
|
|
This is caused by a name that doesn't match the command name regex. |
125
|
|
|
""" |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
class InvalidEventName(PincerError): |
129
|
|
|
"""Exception raised when the event name is not a valid event. |
130
|
|
|
This can be because the event name did not begin with an ``on_`` or |
131
|
|
|
because its not a valid event in the library. |
132
|
|
|
""" |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
class InvalidUrlError(PincerError, ValueError): |
136
|
|
|
"""Exception raised when an invalid url has been provided.""" |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
class EmbedFieldError(PincerError, ValueError): |
140
|
|
|
"""Exception that is raised when an embed field is too large.""" |
141
|
|
|
|
142
|
|
|
@classmethod |
143
|
|
|
def from_desc(cls, _type: str, max_size: int, cur_size: int): |
144
|
|
|
"""Create an instance by description. |
145
|
|
|
|
146
|
|
|
Parameters |
147
|
|
|
---------- |
148
|
|
|
_type :class:`str` |
149
|
|
|
The type/name of the field. |
150
|
|
|
max_si :class:`int` |
151
|
|
|
The maximum size of the field. |
152
|
|
|
cur_size :class:`int` |
153
|
|
|
The current size of the field. |
154
|
|
|
""" |
155
|
|
|
return cls( |
156
|
|
|
f"{_type} can have a maximum length of {max_size}." |
157
|
|
|
f" (Current size: {cur_size})" |
158
|
|
|
) |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
class TaskError(PincerError): |
162
|
|
|
"""Base class for exceptions that are related to tasks. |
163
|
|
|
|
164
|
|
|
Attributes |
165
|
|
|
---------- |
166
|
|
|
task: :class:`~utils.tasks.Task` |
167
|
|
|
The task that raised the exception. |
168
|
|
|
""" |
169
|
|
|
|
170
|
|
|
def __init__(self, message: str, task=None): |
171
|
|
|
self.task = task |
172
|
|
|
super().__init__(message) |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
class TaskAlreadyRunning(TaskError): |
176
|
|
|
"""Exception that is raised when the user tries to start a running task.""" |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
class TaskCancelError(TaskError): |
180
|
|
|
"""Exception that is raised when a task cannot be cancelled.""" |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
class TaskIsNotCoroutine(TaskError): |
184
|
|
|
"""Exception that is raised when the provided function for a task is not |
185
|
|
|
a coroutine. |
186
|
|
|
""" |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
class TaskInvalidDelay(TaskError): |
190
|
|
|
"""Exception that is raised when the provided delay is invalid.""" |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
class DispatchError(PincerError): |
194
|
|
|
"""Base exception class for all errors which are specifically related |
195
|
|
|
to the dispatcher. |
196
|
|
|
""" |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
class _InternalPerformReconnectError(DispatchError): |
200
|
|
|
"""Internal helper exception which on raise lets the client reconnect.""" |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
class DisallowedIntentsError(DispatchError): |
204
|
|
|
"""Invalid gateway intent got provided. |
205
|
|
|
Make sure your client has the enabled intent. |
206
|
|
|
""" |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
class InvalidTokenError(DispatchError, ValueError): |
210
|
|
|
"""Exception raised when the authorization token is invalid.""" |
211
|
|
|
|
212
|
|
|
def __init__(self, hint: Optional[str] = None): |
213
|
|
|
hint = hint or '' |
214
|
|
|
|
215
|
|
|
super(InvalidTokenError, self).__init__( |
216
|
|
|
"The given token is not a valid token.\n" + hint |
217
|
|
|
) |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
class HeartbeatError(DispatchError): |
221
|
|
|
"""Exception raised due to a problem with websocket heartbeat.""" |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
class UnavailableGuildError(PincerError): |
225
|
|
|
"""Exception raised due to a guild being unavailable. |
226
|
|
|
This is caused by a discord outage. |
227
|
|
|
""" |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
# Discord HTTP Errors |
231
|
|
|
# `developers/docs/topics/opcodes-and-status-codes#http` |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
class HTTPError(PincerError): |
235
|
|
|
"""HTTP Exception base class.""" |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
class NotModifiedError(HTTPError): |
239
|
|
|
"""Error code 304.""" |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
class BadRequestError(HTTPError): |
243
|
|
|
"""Error code 400.""" |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
class UnauthorizedError(HTTPError): |
247
|
|
|
"""Error code 401.""" |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
class ForbiddenError(HTTPError): |
251
|
|
|
"""Error code 403.""" |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
class NotFoundError(HTTPError): |
255
|
|
|
"""Error code 404.""" |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
class MethodNotAllowedError(HTTPError): |
259
|
|
|
"""Error code 405.""" |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
class RateLimitError(HTTPError): |
263
|
|
|
"""Error code 429.""" |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
class GatewayError(HTTPError): |
267
|
|
|
"""Error code 502.""" |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
class ServerError(HTTPError): |
271
|
|
|
"""Error code 5xx.""" |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
class NotFoundError(HTTPError): |
275
|
|
|
"""Error code 404.""" |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
class MethodNotAllowedError(HTTPError): |
279
|
|
|
"""Error code 405.""" |
280
|
|
|
|
281
|
|
|
|
282
|
|
|
class RateLimitError(HTTPError): |
283
|
|
|
"""Error code 429.""" |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
class GatewayError(HTTPError): |
287
|
|
|
"""Error code 502.""" |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
class ServerError(HTTPError): |
291
|
|
|
""" |
292
|
|
|
Error code 5xx. |
293
|
|
|
|
|
|
|
|