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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use std::io::Error as IoError;
use std::str::Utf8Error;
use base64::DecodeError;
use kuska_handshake::async_std::Error as HandshakeError;
use kuska_ssb::api::Error as ApiError;
use kuska_ssb::feed::Error as FeedError;
use kuska_ssb::rpc::Error as RpcError;
use serde_json::Error as JsonError;
#[derive(Debug)]
pub enum GolgiError {
DecodeBase64(DecodeError),
Io {
source: IoError,
context: String,
},
Handshake(HandshakeError),
Api(ApiError),
Feed(FeedError),
Rpc(RpcError),
Sbot(String),
SerdeJson(JsonError),
ContentType(String),
Utf8Parse {
source: Utf8Error,
},
}
impl std::error::Error for GolgiError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
GolgiError::DecodeBase64(ref err) => Some(err),
GolgiError::Io { ref source, .. } => Some(source),
GolgiError::Handshake(_) => None,
GolgiError::Api(ref err) => Some(err),
GolgiError::Feed(ref err) => Some(err),
GolgiError::Rpc(ref err) => Some(err),
GolgiError::Sbot(_) => None,
GolgiError::SerdeJson(ref err) => Some(err),
GolgiError::ContentType(_) => None,
GolgiError::Utf8Parse { ref source } => Some(source),
}
}
}
impl std::fmt::Display for GolgiError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
GolgiError::DecodeBase64(_) => write!(f, "Failed to decode base64"),
GolgiError::Io { ref context, .. } => write!(f, "IO error: {}", context),
GolgiError::Handshake(ref err) => write!(f, "Handshake failure: {}", err),
GolgiError::Api(ref err) => write!(f, "SSB API failure: {}", err),
GolgiError::Feed(ref err) => write!(f, "SSB feed error: {}", err),
GolgiError::Rpc(ref err) => write!(f, "SSB RPC failure: {}", err),
GolgiError::Sbot(ref err) => write!(f, "Sbot returned an error response: {}", err),
GolgiError::SerdeJson(_) => write!(f, "Failed to serialize JSON slice"),
GolgiError::ContentType(ref err) => write!(
f,
"Failed to decode typed message from ssb message content: {}",
err
),
GolgiError::Utf8Parse { source } => {
write!(f, "Failed to deserialize UTF8 from bytes: {}", source)
}
}
}
}
impl From<DecodeError> for GolgiError {
fn from(err: DecodeError) -> Self {
GolgiError::DecodeBase64(err)
}
}
impl From<HandshakeError> for GolgiError {
fn from(err: HandshakeError) -> Self {
GolgiError::Handshake(err)
}
}
impl From<ApiError> for GolgiError {
fn from(err: ApiError) -> Self {
GolgiError::Api(err)
}
}
impl From<FeedError> for GolgiError {
fn from(err: FeedError) -> Self {
GolgiError::Feed(err)
}
}
impl From<RpcError> for GolgiError {
fn from(err: RpcError) -> Self {
GolgiError::Rpc(err)
}
}
impl From<JsonError> for GolgiError {
fn from(err: JsonError) -> Self {
GolgiError::SerdeJson(err)
}
}
impl From<Utf8Error> for GolgiError {
fn from(err: Utf8Error) -> Self {
GolgiError::Utf8Parse { source: err }
}
}