1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Debug)]
7pub struct ProcessCapture {
8 pub stdout: String,
10 pub stderr: String,
12}
13
14#[derive(Error, Debug)]
16#[non_exhaustive]
17pub enum TmpPostgrustError {
18 #[error("subprocess failed to execute")]
20 ExecSubprocessFailed {
21 #[source]
23 source: std::io::Error,
24 command: String,
26 },
27 #[error("subprocess failed to spawn")]
29 SpawnSubprocessFailed(#[source] std::io::Error),
30 #[error("initdb failed")]
32 InitDBFailed(ProcessCapture),
33 #[error("copying cached database failed, file not found")]
35 CopyCachedInitDBFailedFileNotFound(#[source] std::io::Error),
36 #[error("copying cached database failed, could not read file type")]
38 CopyCachedInitDBFailedCouldNotReadFileType(#[source] std::io::Error),
39 #[error("copying cached database failed, could not strip path prefix")]
41 CopyCachedInitDBFailedCouldNotStripPathPrefix(#[source] std::path::StripPrefixError),
42 #[cfg(feature = "tokio-process")]
44 #[error("copying cached database failed, failed to join cp process")]
45 CopyCachedInitDBFailedJoinError(#[source] tokio::task::JoinError),
46 #[error("createdb failed")]
48 CreateDBFailed(ProcessCapture),
49 #[error("failed to write postgresql.conf")]
51 CreateConfigFailed(#[source] std::io::Error),
52 #[error("failed to find temporary data directory")]
54 EmptyDataDirectory,
55 #[error("failed to create unix socket directory")]
57 CreateSocketDirFailed(#[source] std::io::Error),
58 #[error("failed to create cache directory")]
60 CreateCacheDirFailed(#[source] std::io::Error),
61 #[error("failed to create cache directory")]
63 CreateDataDirFailed(#[source] std::io::Error),
64 #[error("updating directory permission to non-root failed")]
66 UpdatingPermissionsFailed(ProcessCapture),
67 #[error("failed to run database migrations")]
69 MigrationsFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
70 #[error("could not find postgres command `{command}`{}", .searched_dir.as_ref().map(|d| format!(" in {}", d.display())).unwrap_or_default())]
72 PostgresCommandNotFound {
73 command: String,
75 searched_dir: Option<PathBuf>,
77 },
78 #[cfg(feature = "tokio-process")]
80 #[error("acquiring process permit failed")]
81 AsyncProcessPermitAcquireError(#[source] tokio::sync::AcquireError),
82}
83
84pub type TmpPostgrustResult<T> = Result<T, TmpPostgrustError>;