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
#[derive(Debug, thiserror::Error)]
pub enum LairError {
#[error("LairError: {0}")]
GhostError(#[from] ghost_actor::GhostError),
#[error("Lair pidfile/process already exists")]
ProcessAlreadyExists,
#[error("IpcClientConnectError: {0} {1}")]
IpcClientConnectError(String, Box<dyn std::error::Error + Send + Sync>),
#[error("Public key not found")]
PubKeyNotFound,
#[error(transparent)]
Other(Box<dyn std::error::Error + Send + Sync>),
}
impl LairError {
pub fn other(
e: impl Into<Box<dyn std::error::Error + Send + Sync>>,
) -> Self {
LairError::Other(e.into())
}
}
impl From<String> for LairError {
fn from(s: String) -> Self {
#[derive(Debug, thiserror::Error)]
struct OtherError(String);
impl std::fmt::Display for OtherError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
LairError::other(OtherError(s))
}
}
impl From<&str> for LairError {
fn from(s: &str) -> Self {
s.to_string().into()
}
}
impl From<LairError> for () {
fn from(_: LairError) {}
}
pub type LairResult<T> = Result<T, LairError>;