1use amq_protocol::{
2 frame::GenError,
3 protocol::AMQPClass,
4};
5use failure::{Backtrace, Context, Fail};
6
7use std::{fmt, io};
8
9use crate::connection_status::ConnectionState;
10
11#[derive(Debug)]
19#[deprecated(note = "use lapin instead")]
20pub struct Error {
21 inner: Context<ErrorKind>,
22}
23
24#[derive(Debug, Fail)]
29#[deprecated(note = "use lapin instead")]
30pub enum ErrorKind {
31 #[fail(display = "invalid protocol method: {:?}", _0)]
32 InvalidMethod(AMQPClass),
33 #[fail(display = "invalid channel: {}", _0)]
34 InvalidChannel(u16),
35 #[fail(display = "connection refused")]
36 ConnectionRefused,
37 #[fail(display = "not connected")]
38 NotConnected,
39 #[fail(display = "unexpected reply")]
40 UnexpectedReply,
41 #[fail(display = "precondition failed")]
42 PreconditionFailed,
43 #[fail(display = "The maximum number of channels for this connection has been reached")]
44 ChannelLimitReached,
45 #[fail(display = "invalid connection state: {:?}", _0)]
46 InvalidConnectionState(ConnectionState),
47 #[fail(display = "Failed to parse: {}", _0)]
48 ParsingError(String),
49 #[fail(display = "Failed to serialise: {:?}", _0)]
50 SerialisationError(#[fail(cause)] GenError),
51 #[fail(display = "IO error: {:?}", _0)]
52 IOError(#[fail(cause)] io::Error),
53 #[fail(display = "IO loop error")]
54 IoLoopError,
55 #[doc(hidden)]
63 #[fail(display = "lapin_async::error::ErrorKind::__Nonexhaustive: this should not be printed")]
64 __Nonexhaustive,
65}
66
67impl Error {
68 #[deprecated(note = "use lapin instead")]
70 pub fn kind(&self) -> &ErrorKind {
71 self.inner.get_context()
72 }
73}
74
75impl Fail for Error {
76 fn cause(&self) -> Option<&dyn Fail> {
77 self.inner.cause()
78 }
79
80 fn backtrace(&self) -> Option<&Backtrace> {
81 self.inner.backtrace()
82 }
83}
84
85impl fmt::Display for Error {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 fmt::Display::fmt(&self.inner, f)
88 }
89}
90
91impl From<ErrorKind> for Error {
92 fn from(kind: ErrorKind) -> Error {
93 Error { inner: Context::new(kind) }
94 }
95}
96
97impl From<Context<ErrorKind>> for Error {
98 fn from(inner: Context<ErrorKind>) -> Error {
99 Error { inner }
100 }
101}