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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
use std::sync::Arc;
use jid::JID;
use lampada::error::{ConnectionError, ReadError, WriteError};
use stanza::client::{Stanza, iq::Query};
use thiserror::Error;
pub use lampada::error::CommandError;
// for the client logic impl
#[derive(Debug, Error, Clone)]
pub enum Error {
#[error("core error: {0}")]
Connection(#[from] ConnectionError),
#[error("received unrecognized/unsupported content")]
UnrecognizedContent,
// TODO: include content
// UnrecognizedContent(peanuts::element::Content),
#[error("iq receive error: {0}")]
Iq(#[from] IqError),
// TODO: change to Connecting(ConnectingError)
#[error("connecting: {0}")]
Connecting(#[from] ConnectionJobError),
#[error("presence: {0}")]
Presence(#[from] PresenceError),
#[error("set status: {0}")]
SetStatus(#[from] StatusError),
// TODO: have different ones for get/update/set
#[error("roster: {0}")]
Roster(#[from] RosterError),
#[error("stream error: {0}")]
Stream(#[from] stanza::stream::Error),
#[error("message send error: {0}")]
MessageSend(#[from] MessageSendError),
#[error("message receive error: {0}")]
MessageRecv(#[from] MessageRecvError),
#[error("subscripbe error: {0}")]
Subscribe(#[from] SubscribeError),
#[error("publish error: {0}")]
Publish(#[from] PublishError),
}
#[derive(Debug, Error, Clone)]
pub enum MessageSendError {
#[error("could not add to message history: {0}")]
MessageHistory(#[from] DatabaseError),
#[error("could not mark chat as chatted: {0}")]
MarkChatAsChatted(DatabaseError),
#[error("could not get client user details: {0}")]
GetUserDetails(DatabaseError),
#[error("writing message to connection: {0}")]
Write(#[from] WriteError),
}
#[derive(Debug, Error, Clone)]
pub enum MessageRecvError {
#[error("could not add to message history: {0}")]
MessageHistory(#[from] DatabaseError),
#[error("missing from")]
MissingFrom,
#[error("could not update user nick: {0}")]
NickUpdate(DatabaseError),
}
#[derive(Debug, Error, Clone)]
pub enum StatusError {
#[error("cache: {0}")]
Cache(#[from] DatabaseError),
#[error("stream write: {0}")]
Write(#[from] WriteError),
}
#[derive(Debug, Clone, Error)]
pub enum ConnectionJobError {
// #[error("connection failed: {0}")]
// ConnectionFailed(#[from] luz::Error),
#[error("failed roster retreival: {0}")]
RosterRetreival(#[from] RosterError),
#[error("failed to send available presence: {0}")]
SendPresence(#[from] WriteError),
#[error("cached status: {0}")]
StatusCacheError(#[from] DatabaseError),
}
#[derive(Debug, Error, Clone)]
pub enum RosterError {
#[error("cache: {0}")]
Cache(#[from] DatabaseError),
#[error("iq response: {0}")]
IqResponse(#[from] IqRequestError),
#[error("stream write: {0}")]
Write(#[from] WriteError),
// TODO: display for stanza, to show as xml, same for read error types.
#[error("unexpected reply: {0:?}")]
UnexpectedStanza(Stanza),
#[error("stanza error: {0}")]
StanzaError(#[from] stanza::client::error::Error),
#[error("could not reply to roster push: {0}")]
PushReply(WriteError),
}
#[derive(Debug, Error, Clone)]
pub enum DiscoError {
#[error("write error: {0}")]
Write(#[from] WriteError),
#[error("iq response: {0}")]
IqResponse(#[from] IqRequestError),
#[error("reply from incorrect entity: {0}")]
IncorrectEntity(JID),
#[error("unexpected reply: {0:?}")]
UnexpectedStanza(Stanza),
#[error("stanza error: {0}")]
StanzaError(#[from] stanza::client::error::Error),
#[error("disco result missing query item")]
MissingQuery,
#[error("disco error missing error")]
MissingError,
#[error("received mismatched query")]
MismatchedQuery(Query),
}
#[derive(Debug, Error, Clone)]
pub enum IqRequestError {
#[error("sending request: {0}")]
Write(#[from] WriteError),
#[error("receiving expected response: {0}")]
Read(#[from] ReadError),
}
#[derive(Debug, Error, Clone)]
pub enum ResponseError {
#[error("no matching id: {0}")]
NoMatchingId(String),
}
#[derive(Debug, Error, Clone)]
#[error("database error: {0}")]
pub struct DatabaseError(pub Arc<sqlx::Error>);
impl From<sqlx::Error> for DatabaseError {
fn from(e: sqlx::Error) -> Self {
Self(Arc::new(e))
}
}
impl From<sqlx::Error> for DatabaseOpenError {
fn from(e: sqlx::Error) -> Self {
Self::Error(Arc::new(e))
}
}
#[derive(Debug, Error, Clone)]
// TODO: should probably have all iq query related errors here, including read, write, stanza error, etc.
pub enum IqError {
#[error("writing response: {0}")]
WriteError(#[from] WriteError),
#[error("receiving response: `{0}`")]
ReceivedResponse(#[from] ResponseError),
#[error("incorrect addressee: {0}")]
IncorrectAddressee(jid::JID),
}
#[derive(Debug, Error, Clone)]
pub enum DatabaseOpenError {
#[error("error: {0}")]
Error(Arc<sqlx::Error>),
#[error("migration: {0}")]
Migration(Arc<sqlx::migrate::MigrateError>),
#[error("io: {0}")]
Io(Arc<tokio::io::Error>),
#[error("invalid path")]
InvalidPath,
}
impl From<sqlx::migrate::MigrateError> for DatabaseOpenError {
fn from(e: sqlx::migrate::MigrateError) -> Self {
Self::Migration(Arc::new(e))
}
}
impl From<tokio::io::Error> for DatabaseOpenError {
fn from(e: tokio::io::Error) -> Self {
Self::Io(Arc::new(e))
}
}
#[derive(Debug, Error, Clone)]
pub enum SubscribeError {
#[error("write: {0}")]
Write(#[from] WriteError),
#[error("fetching client user details: {0}")]
Database(#[from] DatabaseError),
}
#[derive(Debug, Error, Clone)]
pub enum PresenceError {
#[error("unsupported")]
Unsupported,
#[error("missing from")]
MissingFrom,
#[error("stanza error: {0}")]
StanzaError(#[from] stanza::client::error::Error),
}
#[derive(Debug, Error, Clone)]
pub enum PublishError {
#[error("received mismatched query")]
MismatchedQuery(Query),
#[error("missing query")]
MissingQuery,
#[error("stanza errors: {0:?}")]
StanzaErrors(Vec<stanza::client::error::Error>),
#[error("reply from incorrect entity: {0}")]
IncorrectEntity(JID),
#[error("unexpected stanza: {0:?}")]
UnexpectedStanza(Stanza),
#[error("iq response: {0}")]
IqResponse(#[from] IqRequestError),
}
#[derive(Debug, Error, Clone)]
pub enum NickError {
#[error("publishing nick: {0}")]
Publish(#[from] CommandError<PublishError>),
#[error("updating database: {0}")]
Database(#[from] DatabaseError),
#[error("disconnected")]
Disconnected,
}
|