use postgresql_archive::ArchiveError;
use std::string::FromUtf8Error;
use thiserror::Error;
pub type Result<T, E = EmbeddedError> = core::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum EmbeddedError {
#[error(transparent)]
ArchiveError(anyhow::Error),
#[error("Archive hash [{archive_hash}] does not match expected hash [{hash}]")]
ArchiveHashMismatch { archive_hash: String, hash: String },
#[error("Archive not found for version [{0}]")]
ArchiveNotFound(String),
#[error("Command error: stdout={stdout}; stderr={stderr}")]
CommandError { stdout: String, stderr: String },
#[error(transparent)]
CreateDatabaseError(anyhow::Error),
#[error(transparent)]
DatabaseExistsError(anyhow::Error),
#[error(transparent)]
DatabaseInitializationError(anyhow::Error),
#[error(transparent)]
DatabaseStartError(anyhow::Error),
#[error(transparent)]
DatabaseStopError(anyhow::Error),
#[error(transparent)]
DropDatabaseError(anyhow::Error),
#[error(transparent)]
IoError(anyhow::Error),
#[error(transparent)]
TimeoutError(anyhow::Error),
}
impl From<ArchiveError> for EmbeddedError {
fn from(error: ArchiveError) -> Self {
EmbeddedError::ArchiveError(error.into())
}
}
impl From<std::io::Error> for EmbeddedError {
fn from(error: std::io::Error) -> Self {
EmbeddedError::IoError(error.into())
}
}
impl From<FromUtf8Error> for EmbeddedError {
fn from(error: FromUtf8Error) -> Self {
EmbeddedError::IoError(error.into())
}
}
#[cfg(feature = "tokio")]
impl From<tokio::time::error::Elapsed> for EmbeddedError {
fn from(error: tokio::time::error::Elapsed) -> Self {
EmbeddedError::TimeoutError(error.into())
}
}