|
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 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 TaskError(PincerError): |
|
137
|
|
|
"""Base class for exceptions that are related to tasks.""" |
|
138
|
|
|
def __init__(self, message: str, task=None): |
|
139
|
|
|
self.task = task |
|
140
|
|
|
super().__init__(message) |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
class TaskAlreadyRunning(TaskError): |
|
144
|
|
|
"""Exception that is raised when the user tries to start a running task""" |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
class TaskCancelError(TaskError): |
|
148
|
|
|
"""Exception that is raised when a task cannot be cancelled.""" |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
class TaskIsNotCoroutine(TaskError): |
|
152
|
|
|
""" |
|
153
|
|
|
Exception that is raised when the provided function for a task is not |
|
154
|
|
|
a coroutine. |
|
155
|
|
|
""" |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
class TaskInvalidDelay(TaskError): |
|
159
|
|
|
"""Exception that is raised when the provided delay is invalid.""" |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
class DispatchError(PincerError): |
|
163
|
|
|
""" |
|
164
|
|
|
Base exception class for all errors which are specifically related |
|
165
|
|
|
to the dispatcher. |
|
166
|
|
|
""" |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
class _InternalPerformReconnectError(DispatchError): |
|
170
|
|
|
"""Internal helper exception which on raise lets the client reconnect.""" |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
class DisallowedIntentsError(DispatchError): |
|
174
|
|
|
""" |
|
175
|
|
|
Invalid gateway intent got provided. |
|
176
|
|
|
Make sure your client has the enabled intent. |
|
177
|
|
|
""" |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
class InvalidTokenError(DispatchError, ValueError): |
|
181
|
|
|
""" |
|
182
|
|
|
Exception raised when the authorization token is invalid. |
|
183
|
|
|
""" |
|
184
|
|
|
|
|
185
|
|
|
def __init__(self, hint: Optional[str] = None): |
|
186
|
|
|
""" |
|
187
|
|
|
:param hint: |
|
188
|
|
|
Additional information about the exception cause. |
|
189
|
|
|
""" |
|
190
|
|
|
hint = hint or '' |
|
191
|
|
|
|
|
192
|
|
|
super(InvalidTokenError, self).__init__( |
|
193
|
|
|
"The given token is not a valid token.\n" + hint |
|
194
|
|
|
) |
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
class HeartbeatError(DispatchError): |
|
198
|
|
|
"""Exception raised due to a problem with websocket heartbeat.""" |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
class UnavailableGuildError(PincerError): |
|
202
|
|
|
""" |
|
203
|
|
|
Exception raised due to a guild being unavailable. |
|
204
|
|
|
This is caused by a discord outage. |
|
205
|
|
|
""" |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
# Discord HTTP Errors |
|
209
|
|
|
# `developers/docs/topics/opcodes-and-status-codes#http` |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
class HTTPError(PincerError): |
|
213
|
|
|
"""HTTP Exception base class.""" |
|
214
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
class NotModifiedError(HTTPError): |
|
217
|
|
|
"""Error code 304.""" |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
class BadRequestError(HTTPError): |
|
221
|
|
|
"""Error code 400.""" |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
class UnauthorizedError(HTTPError): |
|
225
|
|
|
"""Error code 401.""" |
|
226
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
class ForbiddenError(HTTPError): |
|
229
|
|
|
"""Error code 403.""" |
|
230
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
class NotFoundError(HTTPError): |
|
233
|
|
|
"""Error code 404.""" |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
class MethodNotAllowedError(HTTPError): |
|
237
|
|
|
"""Error code 405.""" |
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
class RateLimitError(HTTPError): |
|
241
|
|
|
"""Error code 429.""" |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
class GatewayError(HTTPError): |
|
245
|
|
|
"""Error code 502.""" |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
class ServerError(HTTPError): |
|
249
|
|
|
""" |
|
250
|
|
|
Error code 5xx. |
|
251
|
|
|
Status code is not in the discord API |
|
252
|
|
|
""" |
|
253
|
|
|
|