-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrors.rs
More file actions
85 lines (81 loc) · 3.86 KB
/
Copy patherrors.rs
File metadata and controls
85 lines (81 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::path::PathBuf;
use thiserror::Error;
/// UTF-8 captures of stdout and stderr for child processes used by the library.
#[derive(Debug)]
pub struct ProcessCapture {
/// Capture of stdout from the process
pub stdout: String,
/// Capture of stderr from the process
pub stderr: String,
}
/// Error type for possible postgresql errors.
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum TmpPostgrustError {
/// Catchall error for when a subprocess fails to run to completion
#[error("subprocess failed to execute")]
ExecSubprocessFailed {
/// Underlying I/O Error.
#[source]
source: std::io::Error,
/// Debug formatted string of Command that was attempted.
command: String,
},
/// Catchall error for when a subprocess fails to start
#[error("subprocess failed to spawn")]
SpawnSubprocessFailed(#[source] std::io::Error),
/// Error when `initdb` fails to execute.
#[error("initdb failed")]
InitDBFailed(ProcessCapture),
/// Error when a file to be copied is not found.
#[error("copying cached database failed, file not found")]
CopyCachedInitDBFailedFileNotFound(#[source] std::io::Error),
/// Error when the file type cannot be read when copying the cached db.
#[error("copying cached database failed, could not read file type")]
CopyCachedInitDBFailedCouldNotReadFileType(#[source] std::io::Error),
/// Error when the source directory filepath cannot be stripped.
#[error("copying cached database failed, could not strip path prefix")]
CopyCachedInitDBFailedCouldNotStripPathPrefix(#[source] std::path::StripPrefixError),
/// Error when a copy process cannot be joined.
#[cfg(feature = "tokio-process")]
#[error("copying cached database failed, failed to join cp process")]
CopyCachedInitDBFailedJoinError(#[source] tokio::task::JoinError),
/// Error when `createdb` fails to execute.
#[error("createdb failed")]
CreateDBFailed(ProcessCapture),
/// Error when `postgresql.conf` cannot be written.
#[error("failed to write postgresql.conf")]
CreateConfigFailed(#[source] std::io::Error),
/// Error when the PGDATA directory is empty.
#[error("failed to find temporary data directory")]
EmptyDataDirectory,
/// Error when the temporary unix socket directory cannot be created.
#[error("failed to create unix socket directory")]
CreateSocketDirFailed(#[source] std::io::Error),
/// Error when the cache directory cannot be created.
#[error("failed to create cache directory")]
CreateCacheDirFailed(#[source] std::io::Error),
/// Error when the data directory cannot be created.
#[error("failed to create cache directory")]
CreateDataDirFailed(#[source] std::io::Error),
/// Error when `cp` fails for the initialized database.
#[error("updating directory permission to non-root failed")]
UpdatingPermissionsFailed(ProcessCapture),
/// Error when running migrations failed.
#[error("failed to run database migrations")]
MigrationsFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
/// Error when a required postgres binary cannot be found.
#[error("could not find postgres command `{command}`{}", .searched_dir.as_ref().map(|d| format!(" in {}", d.display())).unwrap_or_default())]
PostgresCommandNotFound {
/// Name of the binary that was not found.
command: String,
/// The explicit directory that was searched, if one was provided.
searched_dir: Option<PathBuf>,
},
/// Error when a process permit cannot be acquired for a new postgres subprocess.
#[cfg(feature = "tokio-process")]
#[error("acquiring process permit failed")]
AsyncProcessPermitAcquireError(#[source] tokio::sync::AcquireError),
}
/// Result type for `TmpPostgrustError`, used by functions in this crate.
pub type TmpPostgrustResult<T> = Result<T, TmpPostgrustError>;