use thiserror::Error;
#[derive(Debug, Error)]
pub enum TestError {
#[error("Failed to start test context: {0}")]
ContextStartFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("Failed to stop test context: {0}")]
ContextStopFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("Hook '{hook_name}' failed: {source}")]
HookFailed {
hook_name: String,
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Test failed: {0}")]
TestFailed(String),
#[error("{0}")]
Other(String),
}
impl TestError {
pub fn context_start_failed<E: std::error::Error + Send + Sync + 'static>(error: E) -> Self {
TestError::ContextStartFailed(Box::new(error))
}
pub fn context_stop_failed<E: std::error::Error + Send + Sync + 'static>(error: E) -> Self {
TestError::ContextStopFailed(Box::new(error))
}
pub fn hook_failed<E: std::error::Error + Send + Sync + 'static>(
hook_name: impl Into<String>,
error: E,
) -> Self {
TestError::HookFailed {
hook_name: hook_name.into(),
source: Box::new(error),
}
}
}