use thiserror::Error;
use crate::{
WireframeError,
codec::CodecError,
connection::ConnectionStateError,
fragment::{FragmentationError, ReassemblyError},
push::{PushConfigError, PushError},
};
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum TestError {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Msg(String),
#[error("wireframe error: {0}")]
Wireframe(WireframeError),
#[cfg(not(loom))]
#[error(transparent)]
Client(#[from] crate::client::ClientError),
#[cfg(not(loom))]
#[error(transparent)]
Server(#[from] crate::server::ServerError),
#[error(transparent)]
Push(#[from] PushError),
#[error(transparent)]
PushConfig(#[from] PushConfigError),
#[error(transparent)]
ConnectionState(#[from] ConnectionStateError),
#[error(transparent)]
Reassembly(#[from] ReassemblyError),
#[error(transparent)]
Fragmentation(#[from] FragmentationError),
#[error(transparent)]
Codec(#[from] CodecError),
#[error(transparent)]
Encode(#[from] bincode::error::EncodeError),
#[error(transparent)]
Decode(#[from] bincode::error::DecodeError),
#[error(transparent)]
Join(#[from] tokio::task::JoinError),
#[error(transparent)]
Timeout(#[from] tokio::time::error::Elapsed),
#[error(transparent)]
OneshotRecv(#[from] tokio::sync::oneshot::error::RecvError),
#[error(transparent)]
OneshotTryRecv(#[from] tokio::sync::oneshot::error::TryRecvError),
#[error(transparent)]
MpscTryRecv(#[from] tokio::sync::mpsc::error::TryRecvError),
#[error(transparent)]
ParseInt(#[from] std::num::ParseIntError),
#[error(transparent)]
TryFromInt(#[from] std::num::TryFromIntError),
#[error(transparent)]
Utf8(#[from] std::str::Utf8Error),
#[error(transparent)]
FromUtf8(#[from] std::string::FromUtf8Error),
#[error(transparent)]
AddrParse(#[from] std::net::AddrParseError),
}
impl From<String> for TestError {
fn from(value: String) -> Self { Self::Msg(value) }
}
impl From<&str> for TestError {
fn from(value: &str) -> Self { Self::Msg(value.to_string()) }
}
impl From<WireframeError> for TestError {
fn from(value: WireframeError) -> Self { Self::Wireframe(value) }
}
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for TestError {
fn from(err: tokio::sync::mpsc::error::SendError<T>) -> Self { Self::Msg(err.to_string()) }
}
impl<T> From<tokio::sync::mpsc::error::TrySendError<T>> for TestError {
fn from(err: tokio::sync::mpsc::error::TrySendError<T>) -> Self { Self::Msg(err.to_string()) }
}
impl From<Box<dyn std::error::Error + Send + Sync>> for TestError {
fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self { Self::Msg(err.to_string()) }
}
pub type TestResult<T = ()> = Result<T, TestError>;