lapin_futures_tls_internal/
error.rs

1use failure::{Backtrace, Context, Fail};
2use lapin_futures;
3
4use std::fmt;
5use std::io;
6
7/// The type of error that can be returned in this crate.
8///
9/// Instead of implementing the `Error` trait provided by the standard library,
10/// it implemented the `Fail` trait provided by the `failure` crate. Doing so
11/// means that this type guaranteed to be both sendable and usable across
12/// threads, and that you'll be able to use the downcasting feature of the
13/// `failure::Error` type.
14#[derive(Debug)]
15#[deprecated(note = "use lapin directly instead")]
16pub struct Error {
17    inner: Context<ErrorKind>,
18}
19
20/// The different kinds of errors that can be reported.
21///
22/// Even though we expose the complete enumeration of possible error variants, it is not
23/// considered stable to exhaustively match on this enumeration: do it at your own risk.
24#[derive(Debug, Fail)]
25#[deprecated(note = "use lapin directly instead")]
26pub enum ErrorKind {
27    /// Failure to parse an Uri
28    #[fail(display = "Uri parsing error: {:?}", _0)]
29    UriParsingError(String),
30    /// Failure to resolve a domain name
31    #[fail(display = "Couldn't resolve domain name: {}", _0)]
32    InvalidDomainName(String),
33    /// Failure to connect
34    #[fail(display = "Failed to connect: {}", _0)]
35    ConnectionFailed(#[fail(cause)] io::Error),
36    /// Error from lapin_futures
37    #[fail(display = "Protocol error: {:?}", _0)]
38    ProtocolError(#[fail(cause)] lapin_futures::error::Error),
39    /// A hack to prevent developers from exhaustively match on the enum's variants
40    ///
41    /// The purpose of this variant is to let the `ErrorKind` enumeration grow more variants
42    /// without it being a breaking change for users. It is planned for the language to provide
43    /// this functionnality out of the box, though it has not been [stabilized] yet.
44    ///
45    /// [stabilized]: https://github.com/rust-lang/rust/issues/44109
46    #[doc(hidden)]
47    #[fail(display = "lapin_futures_tls_internal::error::ErrorKind::__Nonexhaustive: this should not be printed")]
48    __Nonexhaustive,
49}
50
51impl Error {
52    /// Return the underlying `ErrorKind`
53    #[deprecated(note = "use lapin directly instead")]
54    pub fn kind(&self) -> &ErrorKind {
55        self.inner.get_context()
56    }
57}
58
59impl Fail for Error {
60    fn cause(&self) -> Option<&dyn Fail> {
61        self.inner.cause()
62    }
63
64    fn backtrace(&self) -> Option<&Backtrace> {
65        self.inner.backtrace()
66    }
67}
68
69impl fmt::Display for Error {
70    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71        fmt::Display::fmt(&self.inner, f)
72    }
73}
74
75impl From<ErrorKind> for Error {
76    fn from(kind: ErrorKind) -> Error {
77        Error { inner: Context::new(kind) }
78    }
79}
80
81impl From<Context<ErrorKind>> for Error {
82    fn from(inner: Context<ErrorKind>) -> Error {
83        Error { inner: inner }
84    }
85}