use snafu::Snafu;
use std::{io, result};
use url::Url;
pub type Result<T, E = Error> = result::Result<T, E>;
#[derive(Snafu, Debug)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
#[snafu(display("could not parse url: {}", source))]
UrlParseError { source: url::ParseError },
#[snafu(display("amiquip built without TLS support"))]
TlsFeatureNotEnabled,
#[snafu(display(
"insecure URL passed to method that only allows secure connections: {}",
url
))]
InsecureUrl { url: Url },
#[snafu(display("underlying socket closed unexpectedly"))]
UnexpectedSocketClose,
#[snafu(display("I/O error while reading socket: {}", source))]
IoErrorReadingSocket { source: io::Error },
#[snafu(display("I/O error while writing socket: {}", source))]
IoErrorWritingSocket { source: io::Error },
#[snafu(display("received malformed data - expected AMQP frame"))]
MalformedFrame,
#[snafu(display("URL did not resolve to an IP address: {}", url))]
UrlNoSocketAddrs { url: Url },
#[snafu(display("failed to resolve IP address of {}: {}", url, source))]
ResolveUrlToSocketAddr { url: Url, source: io::Error },
#[snafu(display("failed to connect to {}: {}", url, source))]
FailedToConnect { url: Url, source: io::Error },
#[snafu(display("cannot specify port for URL {}", url))]
SpecifyUrlPort { url: Url },
#[snafu(display("invalid scheme for URL {}: expected `amqp` or `amqps`", url))]
InvalidUrlScheme { url: Url },
#[snafu(display("invalid URL (missing domain): {}", url))]
UrlMissingDomain { url: Url },
#[snafu(display("URL contains extraneous path segments: {}", url))]
ExtraUrlPathSegments { url: Url },
#[snafu(display("could not parse heartbeat parameter of URL {}: {}", url, source))]
UrlParseHeartbeat {
url: Url,
source: std::num::ParseIntError,
},
#[snafu(display("could not parse channel_max parameter of URL {}: {}", url, source))]
UrlParseChannelMax {
url: Url,
source: std::num::ParseIntError,
},
#[snafu(display(
"could not parse connection_timeout parameter of URL {}: {}",
url,
source
))]
UrlParseConnectionTimeout {
url: Url,
source: std::num::ParseIntError,
},
#[snafu(display(
"invalid auth mechanism for URL {}: {} (expected `external`)",
url,
mechanism
))]
UrlInvalidAuthMechanism { url: Url, mechanism: String },
#[snafu(display("unsupported parameter in URL {}: {}", url, parameter))]
UrlUnsupportedParameter { url: Url, parameter: String },
#[snafu(display("failed to create polling handle: {}", source))]
CreatePollHandle { source: io::Error },
#[snafu(display("failed to register object with polling handle: {}", source))]
RegisterWithPollHandle { source: io::Error },
#[snafu(display("failed to deregister object with polling handle: {}", source))]
DeregisterWithPollHandle { source: io::Error },
#[snafu(display("failed to poll: {}", source))]
FailedToPoll { source: io::Error },
#[cfg(feature = "native-tls")]
#[snafu(display("TLS handshake failed: {}", source))]
TlsHandshake { source: native_tls::Error },
#[cfg(feature = "native-tls")]
#[snafu(display("could not create TLS connector: {}", source))]
CreateTlsConnector { source: native_tls::Error },
#[snafu(display(
"requested auth mechanism unavailable (available = {}, requested = {})",
available,
requested
))]
UnsupportedAuthMechanism {
available: String,
requested: String,
},
#[snafu(display(
"requested locale unavailable (available = {}, requested = {})",
available,
requested
))]
UnsupportedLocale {
available: String,
requested: String,
},
#[snafu(display(
"requested frame max is too small (min = {}, requested = {})",
min,
requested
))]
FrameMaxTooSmall { min: u32, requested: u32 },
#[snafu(display("timeout occurred while waiting for TCP connection"))]
ConnectionTimeout,
#[snafu(display("SASL secure/secure-ok exchanges are not supported"))]
SaslSecureNotSupported,
#[snafu(display("invalid credentials"))]
InvalidCredentials,
#[snafu(display("missed heartbeats from server"))]
MissedServerHeartbeats,
#[snafu(display("server closed connection (code={} message={})", code, message))]
ServerClosedConnection { code: u16, message: String },
#[snafu(display("client closed connection"))]
ClientClosedConnection,
#[snafu(display(
"server closed channel {} (code={}, message={})",
channel_id,
code,
message
))]
ServerClosedChannel {
channel_id: u16,
code: u16,
message: String,
},
#[snafu(display("channel has been closed"))]
ClientClosedChannel,
#[snafu(display("i/o loop thread tried to communicate with a nonexistent client"))]
EventLoopClientDropped,
#[snafu(display("i/o loop dropped sending side of a channel"))]
EventLoopDropped,
#[snafu(display("AMQP protocol error - received unexpected frame"))]
FrameUnexpected,
#[snafu(display("fork failed: {}", source))]
ForkFailed { source: io::Error },
#[snafu(display("no more channel ids are available"))]
ExhaustedChannelIds,
#[snafu(display("requested channel id ({}) is unavailable", channel_id))]
UnavailableChannelId { channel_id: u16 },
#[snafu(display("internal client exception - received unhandled frames from server"))]
ClientException,
#[snafu(display("received message for nonexistent channel {}", channel_id))]
ReceivedFrameWithBogusChannelId { channel_id: u16 },
#[snafu(display("I/O thread panicked"))]
IoThreadPanic,
#[snafu(display(
"server sent duplicate consumer tag for channel {}: {}",
channel_id,
consumer_tag
))]
DuplicateConsumerTag {
channel_id: u16,
consumer_tag: String,
},
#[snafu(display(
"received delivery with unknown consumer tag for channel {}: {}",
channel_id,
consumer_tag
))]
UnknownConsumerTag {
channel_id: u16,
consumer_tag: String,
},
#[doc(hidden)]
__Nonexhaustive,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn our_error_impls_std_error() {
fn is_err<T: std::error::Error>() {}
is_err::<Error>();
}
}