djs_rs/error.rs
1//! The error type of the high-level client.
2
3/// An error that stops [`Client::login`](crate::Client::login).
4///
5/// discord.js counterpart: none (`Client#login` rejects with the error that stopped it).
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 /// A REST request needed to start the client failed (for example fetching the gateway URL
10 /// with an invalid token).
11 #[error("a REST request failed")]
12 Rest(#[from] djs_rest::Error),
13 /// The gateway connection failed fatally (for example an invalid token or disallowed
14 /// intents).
15 #[error("the gateway connection failed")]
16 #[cfg(feature = "gateway")]
17 #[cfg_attr(docsrs, doc(cfg(feature = "gateway")))]
18 Gateway(#[from] djs_gateway::ReceiveError),
19 /// Discord's daily [session start limit] does not allow starting every shard; nothing was
20 /// connected. The limit (usually 1 000 per day) counts every identify, including those of
21 /// restarts.
22 ///
23 /// [session start limit]: https://docs.discord.com/developers/events/gateway#session-start-limit-object
24 #[error(
25 "not enough session starts left to start {required} shards ({remaining} remaining, \
26 reset in {reset_after:?})"
27 )]
28 SessionStartLimit {
29 /// The number of shards to start.
30 required: u32,
31 /// The session starts left until the reset.
32 remaining: u32,
33 /// The time until the limit resets.
34 reset_after: core::time::Duration,
35 },
36 /// [`Client::login`](crate::Client::login) was called while the client was already running.
37 #[error("the client is already logged in")]
38 AlreadyRunning,
39 /// The connection of a cluster process to its manager failed
40 /// ([`ClientBuilder::cluster`](crate::ClientBuilder::cluster), D-300).
41 #[cfg(feature = "sharding")]
42 #[cfg_attr(docsrs, doc(cfg(feature = "sharding")))]
43 #[error("the connection to the cluster manager failed")]
44 Cluster(#[from] crate::sharding::ClusterError),
45}