#![allow(missing_docs)]
use crate::ResultCode;
#[cfg(feature = "rt-tokio")]
use aerospike_rt::task;
#[derive(Error, Debug)]
pub enum Error {
#[error("Error decoding Base64 encoded value")]
Base64(#[from] ::base64::DecodeError),
#[error("Error interpreting a sequence of u8 as a UTF-8 encoded string.")]
InvalidUtf8(#[from] ::std::str::Utf8Error),
#[error("Error during an I/O operation")]
Io(#[from] ::std::io::Error),
#[error("Error parsing an IP or socket address")]
ParseAddr(#[from] ::std::net::AddrParseError),
#[error("Error parsing an integer")]
ParseInt(#[from] ::std::num::ParseIntError),
#[error("Error returned while hashing a password for user authentication")]
PwHash(#[from] ::pwhash::error::Error),
#[cfg(feature = "rt-tokio")]
#[error("Async runtime error {0}")]
Async(#[from] task::JoinError),
#[error("Bad Server Response: {0}")]
BadResponse(String),
#[error("Unable to communicate with server cluster: {0}")]
Connection(String),
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("Invalid cluster node: {0}")]
InvalidNode(String),
#[error("Too many connections")]
NoMoreConnections,
#[error("Batch error: Index: {0:?}, Result Code: {1:?}, In Doubt: {2}, Node: {3}")]
BatchError(u32, ResultCode, bool, String),
#[error("Batch error: Index: {0:?}, Result Code: {1:?}, In Doubt: {2}, Node: {3}")]
BatchLastError(u32, ResultCode, bool, String),
#[error("Server error: {0:?}, In Doubt: {1}, Node: {2}")]
ServerError(ResultCode, bool, String),
#[error("UDF Bad Response: {0}")]
UdfBadResponse(String),
#[error("Client Timeout: {0}")]
Timeout(String),
#[error("{0}")]
ClientError(String),
#[error("{0}")]
ParsePeersError(String),
#[error("Record stream was terminated by user")]
StreamTerminatedError(),
#[error("{0}\n\t{1}")]
Chain(Box<Error>, Box<Error>),
}
impl Error {
#[must_use]
pub fn chain_error(self, e: &str) -> Error {
Error::Chain(Box::new(Error::ClientError(e.into())), Box::new(self))
}
#[must_use]
pub fn wrap(self, e: Error) -> Error {
Error::Chain(Box::new(e), Box::new(self))
}
}
pub type Result<T> = ::std::result::Result<T, Error>;
macro_rules! log_error_chain {
($err:expr, $($arg:tt)*) => {
error!($($arg)*);
error!("Error: {}", $err);
};
}