1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::shard::Error as ShardError;
use std::{
error::Error as StdError,
fmt::{Display, Formatter, Result as FmtResult},
result::Result as StdResult,
};
use twilight_http::Error as HttpError;
pub type Result<T, E = Error> = StdResult<T, E>;
#[allow(clippy::pub_enum_variant_names)]
#[derive(Debug)]
pub enum Error {
GettingGatewayInfo {
source: HttpError,
},
IdTooLarge {
end: u64,
start: u64,
total: u64,
},
LargeThresholdInvalid {
source: ShardError,
},
ShardDoesNotExist {
id: u64,
},
ShardError {
source: ShardError,
},
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
Self::GettingGatewayInfo { .. } => f.write_str("Getting the gateway info failed"),
Self::IdTooLarge { end, start, total } => write!(
f,
"The shard ID pair {}-{}/{} is mismatched",
start, end, total
),
Self::LargeThresholdInvalid { source } | Self::ShardError { source } => {
write!(f, "{}", source)
}
Self::ShardDoesNotExist { id } => write!(f, "The ID: {} does not exist", id),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Self::GettingGatewayInfo { source } => Some(source),
Self::IdTooLarge { .. } | Self::ShardDoesNotExist { .. } => None,
Self::LargeThresholdInvalid { source } | Self::ShardError { source } => Some(source),
}
}
}