use crate::misc::{
ArrayString, ArrayStringError, ArrayVectorError, BlocksDequeError, DequeueError,
FromRadix10Error, VectorError,
};
#[allow(unused_imports, reason = "Depends on the selection of features")]
use alloc::boxed::Box;
use core::{
fmt::{Debug, Display, Formatter},
ops::RangeInclusive,
};
#[cfg(target_pointer_width = "64")]
const _: () = {
assert!(size_of::<Error>() == 24);
};
#[allow(missing_docs, reason = "Work in progress")]
#[derive(Debug)]
pub enum Error {
#[cfg(feature = "aes-gcm")]
AeadError(aes_gcm::aead::Error),
#[cfg(feature = "argon2")]
Argon2(argon2::Error),
AtoiInvalidBytes,
#[cfg(feature = "chrono")]
ChronoParseError(chrono::ParseError),
#[cfg(feature = "cl-aux")]
ClAux(cl_aux::Error),
#[cfg(feature = "http-cookie")]
Cookie(crate::http::CookieError),
#[cfg(feature = "crypto-common")]
CryptoCommonInvalidLength(crypto_common::InvalidLength),
#[cfg(feature = "base64")]
DecodeError(base64::DecodeError),
#[cfg(feature = "base64")]
DecodeSliceError(base64::DecodeSliceError),
#[cfg(feature = "embassy-net")]
EmbassyNet(embassy_net::tcp::Error),
#[cfg(feature = "base64")]
EncodeSliceError(base64::EncodeSliceError),
#[cfg(feature = "flate2")]
Flate2CompressError(flate2::CompressError),
#[cfg(feature = "flate2")]
Flate2DecompressError(Box<flate2::DecompressError>),
#[cfg(feature = "getrandom")]
GetRandomError(getrandom::Error),
#[cfg(feature = "httparse")]
HttpParse(httparse::Error),
#[cfg(feature = "matchit")]
Matchit(matchit::MatchError),
#[cfg(feature = "matchit")]
MatchitInsertError(Box<matchit::InsertError>),
#[cfg(feature = "digest")]
MacError(digest::MacError),
#[cfg(feature = "mysql")]
MysqlDbError(Box<crate::database::client::mysql::DbError>),
#[cfg(feature = "postgres")]
PostgresDbError(Box<crate::database::client::postgres::DbError>),
#[cfg(feature = "quick-protobuf")]
QuickProtobuf(Box<quick_protobuf::Error>),
#[cfg(feature = "rsa")]
RsaError(Box<rsa::Error>),
#[cfg(feature = "rustls")]
RustlsError(Box<rustls::Error>),
#[cfg(feature = "serde")]
SerdeDeValue(::serde::de::value::Error),
#[cfg(feature = "serde_json")]
SerdeJson(serde_json::Error),
#[cfg(feature = "serde_urlencoded")]
SerdeUrlencodedSer(Box<serde_urlencoded::ser::Error>),
#[cfg(feature = "http-session")]
SessionError(crate::http::SessionError),
#[cfg(feature = "spki")]
SpkiError(Box<spki::Error>),
#[cfg(feature = "tokio")]
TokioJoinError(Box<tokio::task::JoinError>),
#[cfg(feature = "tracing-subscriber")]
TryInitError(tracing_subscriber::util::TryInitError),
#[cfg(feature = "std")]
TryLockError(std::sync::TryLockError<()>),
#[cfg(feature = "uuid")]
UuidError(Box<uuid::Error>),
#[cfg(feature = "x509-certificate")]
X509CertificateError(Box<x509_certificate::X509CertificateError>),
AddrParseError(core::net::AddrParseError),
Fmt(core::fmt::Error),
#[cfg(feature = "std")]
IoError(std::io::Error),
ParseIntError(core::num::ParseIntError),
TryFromIntError(core::num::TryFromIntError),
TryFromSliceError(core::array::TryFromSliceError),
#[cfg(feature = "std")]
VarError(VarError),
Utf8Error(core::str::Utf8Error),
ClosedConnection,
Generic(&'static str),
GenericOwned(Box<str>),
GenericTimeNeedsBackend,
InvalidHardwareTime,
InvalidPartitionedBufferBounds,
InvalidTimeArithmetic,
InvalidUTF8,
InvalidUri,
MissingCaProviders,
NoInnerValue(&'static str),
OutOfBoundsArithmetic,
ProgrammingError,
UnboundedNumber {
expected: RangeInclusive<u32>,
received: u32,
},
UnexpectedBufferState,
UnexpectedBytes {
length: u16,
ty: ArrayString<8>,
},
UnexpectedStreamReadEOF,
UnexpectedStreamWriteEOF,
UnexpectedString {
length: usize,
},
UnexpectedUint {
received: u64,
},
UriCanNotBeOverwritten,
UsizeConversionOverflow,
ArrayStringError(ArrayStringError),
ArrayVectorError(ArrayVectorError),
BlocksQueueError(BlocksDequeError),
#[cfg(feature = "client-api-framework")]
ClientApiFrameworkError(crate::client_api_framework::ClientApiFrameworkError),
#[cfg(feature = "database")]
DatabaseError(crate::database::DatabaseError),
#[cfg(feature = "data-transformation")]
DataTransformationError(crate::data_transformation::DataTransformationError),
FromRadix10Error(FromRadix10Error),
#[cfg(feature = "http")]
HttpError(crate::http::HttpError),
#[cfg(feature = "http2")]
Http2ErrorGoAway(crate::http2::Http2ErrorCode, Option<crate::http2::Http2Error>),
#[cfg(feature = "http2")]
Http2ErrorReset(crate::http2::Http2ErrorCode, Option<crate::http2::Http2Error>, u32),
#[cfg(feature = "mysql")]
MysqlError(crate::database::client::mysql::MysqlError),
#[cfg(feature = "postgres")]
PostgresError(crate::database::client::postgres::PostgresError),
QueueError(DequeueError),
#[cfg(feature = "schema-manager")]
SchemaManagerError(crate::database::schema_manager::SchemaManagerError),
#[cfg(feature = "http-server-framework")]
ServerFrameworkError(crate::http::server_framework::ServerFrameworkError),
VectorError(VectorError),
#[cfg(feature = "web-socket")]
WebSocketError(crate::web_socket::WebSocketError),
}
impl Display for Error {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
<Self as Debug>::fmt(self, f)
}
}
impl core::error::Error for Error {}
impl From<Error> for () {
#[inline]
fn from(_: Error) -> Self {}
}
#[cfg(feature = "aes-gcm")]
impl From<aes_gcm::aead::Error> for Error {
#[inline]
#[track_caller]
fn from(from: aes_gcm::aead::Error) -> Self {
Self::AeadError(from)
}
}
#[cfg(feature = "argon2")]
impl From<argon2::Error> for Error {
#[inline]
#[track_caller]
fn from(from: argon2::Error) -> Self {
Self::Argon2(from)
}
}
#[cfg(feature = "chrono")]
impl From<chrono::ParseError> for Error {
#[inline]
#[track_caller]
fn from(from: chrono::ParseError) -> Self {
Self::ChronoParseError(from)
}
}
#[cfg(feature = "cl-aux")]
impl From<cl_aux::Error> for Error {
#[inline]
fn from(from: cl_aux::Error) -> Self {
Self::ClAux(from)
}
}
#[cfg(feature = "http-cookie")]
impl From<crate::http::CookieError> for Error {
#[inline]
#[track_caller]
fn from(from: crate::http::CookieError) -> Self {
Self::Cookie(from)
}
}
#[cfg(feature = "crypto-common")]
impl From<crypto_common::InvalidLength> for Error {
#[inline]
#[track_caller]
fn from(from: crypto_common::InvalidLength) -> Self {
Self::CryptoCommonInvalidLength(from)
}
}
#[cfg(feature = "base64")]
impl From<base64::DecodeError> for Error {
#[inline]
#[track_caller]
fn from(from: base64::DecodeError) -> Self {
Self::DecodeError(from)
}
}
#[cfg(feature = "base64")]
impl From<base64::DecodeSliceError> for Error {
#[inline]
#[track_caller]
fn from(from: base64::DecodeSliceError) -> Self {
Self::DecodeSliceError(from)
}
}
#[cfg(feature = "embassy-net")]
impl From<embassy_net::tcp::Error> for Error {
#[inline]
fn from(from: embassy_net::tcp::Error) -> Self {
Self::EmbassyNet(from)
}
}
#[cfg(feature = "base64")]
impl From<base64::EncodeSliceError> for Error {
#[inline]
fn from(from: base64::EncodeSliceError) -> Self {
Self::EncodeSliceError(from)
}
}
#[cfg(feature = "flate2")]
impl From<flate2::CompressError> for Error {
#[inline]
fn from(from: flate2::CompressError) -> Self {
Self::Flate2CompressError(from)
}
}
#[cfg(feature = "flate2")]
impl From<flate2::DecompressError> for Error {
#[inline]
fn from(from: flate2::DecompressError) -> Self {
Self::Flate2DecompressError(from.into())
}
}
#[cfg(feature = "getrandom")]
impl From<getrandom::Error> for Error {
#[inline]
fn from(from: getrandom::Error) -> Self {
Self::GetRandomError(from)
}
}
impl From<core::net::AddrParseError> for Error {
#[inline]
fn from(from: core::net::AddrParseError) -> Self {
Self::AddrParseError(from)
}
}
impl From<core::fmt::Error> for Error {
#[inline]
fn from(from: core::fmt::Error) -> Self {
Self::Fmt(from)
}
}
#[cfg(feature = "httparse")]
impl From<httparse::Error> for Error {
#[inline]
fn from(from: httparse::Error) -> Self {
Self::HttpParse(from)
}
}
#[cfg(feature = "matchit")]
impl From<matchit::MatchError> for Error {
#[inline]
fn from(from: matchit::MatchError) -> Self {
Self::Matchit(from)
}
}
#[cfg(feature = "matchit")]
impl From<matchit::InsertError> for Error {
#[inline]
fn from(from: matchit::InsertError) -> Self {
Self::MatchitInsertError(from.into())
}
}
#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
#[inline]
fn from(from: std::io::Error) -> Self {
Self::IoError(from)
}
}
#[cfg(feature = "std")]
impl From<std::env::VarError> for Error {
#[inline]
fn from(from: std::env::VarError) -> Self {
Self::VarError(match from {
std::env::VarError::NotPresent => VarError::NotPresent,
std::env::VarError::NotUnicode(_) => VarError::NotUnicode,
})
}
}
#[cfg(feature = "digest")]
impl From<digest::MacError> for Error {
#[inline]
fn from(from: digest::MacError) -> Self {
Self::MacError(from)
}
}
#[cfg(feature = "mysql")]
impl From<crate::database::client::mysql::DbError> for Error {
#[inline]
fn from(from: crate::database::client::mysql::DbError) -> Self {
Self::MysqlDbError(from.into())
}
}
impl From<core::num::ParseIntError> for Error {
#[inline]
fn from(from: core::num::ParseIntError) -> Self {
Self::ParseIntError(from)
}
}
#[cfg(feature = "postgres")]
impl From<crate::database::client::postgres::DbError> for Error {
#[inline]
fn from(from: crate::database::client::postgres::DbError) -> Self {
Self::PostgresDbError(from.into())
}
}
#[cfg(feature = "quick-protobuf")]
impl From<quick_protobuf::Error> for Error {
#[inline]
fn from(from: quick_protobuf::Error) -> Self {
Self::QuickProtobuf(from.into())
}
}
#[cfg(feature = "rsa")]
impl From<rsa::Error> for Error {
#[inline]
fn from(from: rsa::Error) -> Self {
Self::RsaError(from.into())
}
}
#[cfg(feature = "rustls")]
impl From<rustls::Error> for Error {
#[inline]
fn from(from: rustls::Error) -> Self {
Self::RustlsError(from.into())
}
}
#[cfg(feature = "serde")]
impl From<::serde::de::value::Error> for Error {
#[inline]
fn from(from: ::serde::de::value::Error) -> Self {
Self::SerdeDeValue(from)
}
}
#[cfg(feature = "serde_json")]
impl From<serde_json::Error> for Error {
#[inline]
fn from(from: serde_json::Error) -> Self {
Self::SerdeJson(from)
}
}
#[cfg(feature = "serde_urlencoded")]
impl From<serde_urlencoded::ser::Error> for Error {
#[inline]
fn from(from: serde_urlencoded::ser::Error) -> Self {
Self::SerdeUrlencodedSer(from.into())
}
}
#[cfg(feature = "http-session")]
impl From<crate::http::SessionError> for Error {
#[inline]
fn from(from: crate::http::SessionError) -> Self {
Self::SessionError(from)
}
}
#[cfg(feature = "spki")]
impl From<spki::Error> for Error {
#[inline]
fn from(from: spki::Error) -> Self {
Self::SpkiError(from.into())
}
}
#[cfg(feature = "tokio")]
impl From<tokio::task::JoinError> for Error {
#[inline]
fn from(from: tokio::task::JoinError) -> Self {
Self::TokioJoinError(from.into())
}
}
#[cfg(feature = "tracing-subscriber")]
impl From<tracing_subscriber::util::TryInitError> for Error {
#[inline]
fn from(from: tracing_subscriber::util::TryInitError) -> Self {
Self::TryInitError(from)
}
}
impl From<core::num::TryFromIntError> for Error {
#[inline]
fn from(from: core::num::TryFromIntError) -> Self {
Self::TryFromIntError(from)
}
}
impl From<core::array::TryFromSliceError> for Error {
#[inline]
fn from(from: core::array::TryFromSliceError) -> Self {
Self::TryFromSliceError(from)
}
}
#[cfg(feature = "std")]
impl<T> From<std::sync::TryLockError<T>> for Error {
#[inline]
fn from(from: std::sync::TryLockError<T>) -> Self {
Self::TryLockError(match from {
std::sync::TryLockError::Poisoned(_) => {
std::sync::TryLockError::Poisoned(std::sync::PoisonError::new(()))
}
std::sync::TryLockError::WouldBlock => std::sync::TryLockError::WouldBlock,
})
}
}
#[cfg(feature = "uuid")]
impl From<uuid::Error> for Error {
#[inline]
fn from(value: uuid::Error) -> Self {
Self::UuidError(value.into())
}
}
#[cfg(feature = "x509-certificate")]
impl From<x509_certificate::X509CertificateError> for Error {
#[inline]
fn from(from: x509_certificate::X509CertificateError) -> Self {
Self::X509CertificateError(from.into())
}
}
impl From<ArrayStringError> for Error {
#[inline]
fn from(from: ArrayStringError) -> Self {
Self::ArrayStringError(from)
}
}
impl From<ArrayVectorError> for Error {
#[inline]
fn from(from: ArrayVectorError) -> Self {
Self::ArrayVectorError(from)
}
}
impl From<BlocksDequeError> for Error {
#[inline]
fn from(from: BlocksDequeError) -> Self {
Self::BlocksQueueError(from)
}
}
#[cfg(feature = "http")]
impl From<crate::http::HttpError> for Error {
#[inline]
fn from(from: crate::http::HttpError) -> Self {
Self::HttpError(from)
}
}
#[cfg(feature = "client-api-framework")]
impl From<crate::client_api_framework::ClientApiFrameworkError> for Error {
#[inline]
fn from(from: crate::client_api_framework::ClientApiFrameworkError) -> Self {
Self::ClientApiFrameworkError(from)
}
}
#[cfg(feature = "database")]
impl From<crate::database::DatabaseError> for Error {
#[inline]
fn from(from: crate::database::DatabaseError) -> Self {
Self::DatabaseError(from)
}
}
#[cfg(feature = "data-transformation")]
impl From<crate::data_transformation::DataTransformationError> for Error {
#[inline]
fn from(from: crate::data_transformation::DataTransformationError) -> Self {
Self::DataTransformationError(from)
}
}
impl From<FromRadix10Error> for Error {
#[inline]
fn from(from: FromRadix10Error) -> Self {
Self::FromRadix10Error(from)
}
}
#[cfg(feature = "mysql")]
impl From<crate::database::client::mysql::MysqlError> for Error {
#[inline]
fn from(from: crate::database::client::mysql::MysqlError) -> Self {
Self::MysqlError(from)
}
}
#[cfg(feature = "postgres")]
impl From<crate::database::client::postgres::PostgresError> for Error {
#[inline]
fn from(from: crate::database::client::postgres::PostgresError) -> Self {
Self::PostgresError(from)
}
}
impl From<DequeueError> for Error {
#[inline]
fn from(from: DequeueError) -> Self {
Self::QueueError(from)
}
}
#[cfg(feature = "schema-manager")]
impl From<crate::database::schema_manager::SchemaManagerError> for Error {
#[inline]
fn from(from: crate::database::schema_manager::SchemaManagerError) -> Self {
Self::SchemaManagerError(from)
}
}
#[cfg(feature = "http-server-framework")]
impl From<crate::http::server_framework::ServerFrameworkError> for Error {
#[inline]
fn from(from: crate::http::server_framework::ServerFrameworkError) -> Self {
Self::ServerFrameworkError(from)
}
}
impl From<VectorError> for Error {
#[inline]
fn from(from: VectorError) -> Self {
Self::VectorError(from)
}
}
#[cfg(feature = "web-socket")]
impl From<crate::web_socket::WebSocketError> for Error {
#[inline]
fn from(from: crate::web_socket::WebSocketError) -> Self {
Self::WebSocketError(from)
}
}
#[cfg(feature = "std")]
#[derive(Clone, Copy, Debug)]
pub enum VarError {
NotPresent,
NotUnicode,
}
#[cfg(feature = "serde")]
mod serde {
use alloc::string::ToString;
use core::fmt::Display;
impl serde::ser::Error for crate::Error {
#[inline]
fn custom<T>(msg: T) -> Self
where
T: Display,
{
Self::GenericOwned(msg.to_string().into())
}
}
}