pg_embedded_setup_unpriv/
error.rs1use color_eyre::Report;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, PgEmbeddedError>;
8
9pub type BootstrapResult<T> = std::result::Result<T, BootstrapError>;
11
12pub type PrivilegeResult<T> = std::result::Result<T, PrivilegeError>;
14
15pub type ConfigResult<T> = std::result::Result<T, ConfigError>;
17
18#[derive(Debug, Error)]
20pub enum PgEmbeddedError {
21 #[error("bootstrap failed")]
23 Bootstrap(#[from] BootstrapError),
24 #[error("privilege management failed")]
26 Privilege(#[from] PrivilegeError),
27 #[error("configuration parsing failed")]
29 Config(#[from] ConfigError),
30}
31
32#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
34pub enum BootstrapErrorKind {
35 #[default]
37 Other,
38 WorkerBinaryMissing,
40}
41
42#[derive(Debug, Error)]
44#[error("{report}")]
45pub struct BootstrapError {
46 kind: BootstrapErrorKind,
47 #[source]
48 report: Report,
49}
50
51impl BootstrapError {
52 #[must_use]
55 pub const fn new(kind: BootstrapErrorKind, report: Report) -> Self {
56 Self { kind, report }
57 }
58
59 #[must_use]
61 pub const fn kind(&self) -> BootstrapErrorKind {
62 self.kind
63 }
64
65 pub fn into_report(self) -> Report {
67 self.report
68 }
69}
70
71impl From<Report> for BootstrapError {
72 fn from(report: Report) -> Self {
73 Self::new(BootstrapErrorKind::Other, report)
74 }
75}
76
77impl From<PrivilegeError> for BootstrapError {
78 fn from(err: PrivilegeError) -> Self {
79 let PrivilegeError(report) = err;
80 Self::new(BootstrapErrorKind::Other, report)
81 }
82}
83
84impl From<ConfigError> for BootstrapError {
85 fn from(err: ConfigError) -> Self {
86 let ConfigError(report) = err;
87 Self::new(BootstrapErrorKind::Other, report)
88 }
89}
90
91impl From<PgEmbeddedError> for BootstrapError {
92 fn from(err: PgEmbeddedError) -> Self {
93 match err {
94 PgEmbeddedError::Bootstrap(inner) => inner,
95 PgEmbeddedError::Privilege(inner) => inner.into(),
96 PgEmbeddedError::Config(inner) => inner.into(),
97 }
98 }
99}
100
101#[derive(Debug, Error)]
103#[error(transparent)]
104pub struct PrivilegeError(#[from] Report);
105
106#[derive(Debug, Error)]
108#[error(transparent)]
109pub struct ConfigError(#[from] Report);