use thiserror::Error;
#[derive(Debug)]
pub struct ProcessCapture {
pub stdout: String,
pub stderr: String,
}
#[derive(Error, Debug)]
pub enum TmpPostgrustError {
#[error("subprocess failed to execute")]
ExecSubprocessFailed {
#[source]
source: std::io::Error,
command: String,
},
#[error("subprocess failed to spawn")]
SpawnSubprocessFailed(#[source] std::io::Error),
#[error("initdb failed")]
InitDBFailed(ProcessCapture),
#[error("copying cached database failed, file not found")]
CopyCachedInitDBFailedFileNotFound(#[source] std::io::Error),
#[error("copying cached database failed, could not read file type")]
CopyCachedInitDBFailedCouldNotReadFileType(#[source] std::io::Error),
#[error("copying cached database failed, could not strip path prefix")]
CopyCachedInitDBFailedCouldNotStripPathPrefix(#[source] std::path::StripPrefixError),
#[cfg(feature = "tokio-process")]
#[error("copying cached database failed, failed to join cp process")]
CopyCachedInitDBFailedJoinError(#[source] tokio::task::JoinError),
#[error("createdb failed")]
CreateDBFailed(ProcessCapture),
#[error("failed to write postgresql.conf")]
CreateConfigFailed(#[source] std::io::Error),
#[error("failed to find temporary data directory")]
EmptyDataDirectory,
#[error("failed to create unix socket directory")]
CreateSocketDirFailed(#[source] std::io::Error),
#[error("failed to create cache directory")]
CreateCacheDirFailed(#[source] std::io::Error),
#[error("updating directory permission to non-root failed")]
UpdatingPermissionsFailed(ProcessCapture),
}
pub type TmpPostgrustResult<T> = Result<T, TmpPostgrustError>;