arcbox_container/
error.rs1use arcbox_error::CommonError;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, ContainerError>;
8
9#[derive(Debug, Error)]
11pub enum ContainerError {
12 #[error(transparent)]
14 Common(#[from] CommonError),
15
16 #[error("image error: {0}")]
18 Image(String),
19
20 #[error("volume error: {0}")]
22 Volume(String),
23
24 #[error("runtime error: {0}")]
26 Runtime(String),
27
28 #[error("internal lock poisoned")]
30 LockPoisoned,
31}
32
33impl From<std::io::Error> for ContainerError {
34 fn from(err: std::io::Error) -> Self {
35 Self::Common(CommonError::from(err))
36 }
37}
38
39impl ContainerError {
40 #[must_use]
42 pub fn not_found(resource: impl Into<String>) -> Self {
43 Self::Common(CommonError::not_found(resource))
44 }
45
46 #[must_use]
48 pub fn invalid_state(msg: impl Into<String>) -> Self {
49 Self::Common(CommonError::invalid_state(msg))
50 }
51
52 #[must_use]
54 pub fn config(msg: impl Into<String>) -> Self {
55 Self::Common(CommonError::config(msg))
56 }
57
58 #[must_use]
60 pub fn already_exists(resource: impl Into<String>) -> Self {
61 Self::Common(CommonError::already_exists(resource))
62 }
63
64 #[must_use]
66 pub const fn is_not_found(&self) -> bool {
67 matches!(self, Self::Common(CommonError::NotFound(_)))
68 }
69
70 #[must_use]
72 pub const fn is_invalid_state(&self) -> bool {
73 matches!(self, Self::Common(CommonError::InvalidState(_)))
74 }
75}