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
use crate::net;
use std::fmt;
use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError};
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
ConnectionOpenError(String),
ConnectionCloseError(String),
ConnectionUseError(String),
ChannelOpenError(String),
ChannelCloseError(String),
ChannelUseError(String),
NetworkError(String),
InternalChannelError(String),
}
impl From<net::Error> for Error {
fn from(err: net::Error) -> Self {
Self::NetworkError(err.to_string())
}
}
impl<T> From<SendError<T>> for Error {
fn from(err: SendError<T>) -> Self {
Self::InternalChannelError(err.to_string())
}
}
impl From<RecvError> for Error {
fn from(err: RecvError) -> Self {
Self::InternalChannelError(err.to_string())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::NetworkError(msg) => write!(f, "AMQP network error: {}", msg),
Error::ConnectionOpenError(msg) => write!(f, "AMQP connection open error: {}", msg),
Error::ConnectionCloseError(msg) => write!(f, "AMQP connection close error: {}", msg),
Error::ConnectionUseError(msg) => write!(f, "AMQP connection usage error: {}", msg),
Error::ChannelOpenError(msg) => write!(f, "AMQP channel open error: {}", msg),
Error::ChannelUseError(msg) => write!(f, "AMQP channel close error: {}", msg),
Error::ChannelCloseError(msg) => write!(f, "AMQP channel usage error: {}", msg),
Error::InternalChannelError(msg) => {
write!(f, "internal communication error: {}", msg)
}
}
}
}
impl std::error::Error for Error {}