use std::error::Error;
use crate::core::logs::WaitLogError;
pub use crate::core::{client::ClientError, env::ConfigurationError, ContainerPort};
pub type Result<T> = std::result::Result<T, TestcontainersError>;
#[derive(Debug, thiserror::Error)]
pub enum TestcontainersError {
#[error(transparent)]
Client(#[from] ClientError),
#[error("container is not ready: {0}")]
WaitContainer(#[from] WaitContainerError),
#[error("container '{id}' does not expose port {port}")]
PortNotExposed { id: String, port: ContainerPort },
#[error(transparent)]
MissingInfo(#[from] ContainerMissingInfo),
#[error("exec operation failed: {0}")]
Exec(#[from] ExecError),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("other error: {0}")]
Other(Box<dyn Error + Sync + Send>),
}
#[derive(Debug, thiserror::Error)]
#[error("container '{id}' does not have: {path}")]
pub struct ContainerMissingInfo {
id: String,
path: String,
}
#[derive(Debug, thiserror::Error)]
pub enum ExecError {
#[error("exec process exited with code {actual}, expected {expected}")]
ExitCodeMismatch { expected: i64, actual: i64 },
#[error("failed to wait for exec log: {0}")]
WaitLog(#[from] WaitLogError),
}
#[derive(Debug, thiserror::Error)]
pub enum WaitContainerError {
#[error("failed to wait for container log: {0}")]
WaitLog(#[from] WaitLogError),
#[error("container state is unavailable")]
StateUnavailable,
#[error("container is not ready: {0}")]
#[cfg(feature = "http_wait_plain")]
#[cfg_attr(docsrs, doc(cfg(feature = "http_wait_plain")))]
HttpWait(#[from] crate::core::wait::http_strategy::HttpWaitError),
#[error("healthcheck is not configured for container: {0}")]
HealthCheckNotConfigured(String),
#[error("container is unhealthy")]
Unhealthy,
#[error("container startup timeout")]
StartupTimeout,
#[error("container exited with unexpected code: expected {expected}, actual {actual:?}")]
UnexpectedExitCode { expected: i64, actual: Option<i64> },
}
impl TestcontainersError {
pub fn other<E>(error: E) -> Self
where
E: Into<Box<dyn Error + Send + Sync>>,
{
Self::Other(error.into())
}
}
impl ContainerMissingInfo {
pub(crate) fn new(id: impl Into<String>, path: impl Into<String>) -> Self {
Self {
id: id.into(),
path: path.into(),
}
}
}