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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Error types for the core layer.
use arcbox_error::CommonError;
use thiserror::Error;
/// Result type alias for core operations.
pub type Result<T> = std::result::Result<T, CoreError>;
/// Errors that can occur in core operations.
#[derive(Debug, Error)]
pub enum CoreError {
/// Common errors (I/O, config, not found, etc.).
#[error(transparent)]
Common(#[from] CommonError),
/// VMM-layer error (hypervisor, devices, boot).
#[error("VMM error: {0}")]
Vmm(#[from] arcbox_vmm::VmmError),
/// Snapshot error.
#[error("snapshot error: {0}")]
Snapshot(#[from] arcbox_vmm::SnapshotError),
/// VM management error (registry, lifecycle).
#[error("VM error: {0}")]
Vm(String),
/// Machine error.
#[error("machine error: {0}")]
Machine(String),
/// Error reported by the guest agent over the vsock wire, carrying an
/// HTTP-style status code (400/404/409/412/500/503) that the API layer
/// maps onto the matching gRPC status.
#[error("{message}")]
Agent {
/// HTTP-style status code from the agent's `ErrorResponse`.
code: i32,
/// Human-readable error message.
message: String,
},
/// Persistence deserialization error.
#[error("persistence error: {0}")]
Persistence(#[from] toml::de::Error),
/// An internal RwLock was poisoned by a panicking thread.
#[error("internal lock poisoned")]
LockPoisoned,
/// Filesystem error.
#[error("filesystem error: {0}")]
Fs(#[from] arcbox_fs::FsError),
/// Network error.
#[error("network error: {0}")]
Net(#[from] arcbox_net::NetError),
/// Published-image registry error (index/manifest fetch, reference
/// parsing, name validation) shared by the macOS base-image and Linux
/// machine-image flows.
#[error("image error: {0}")]
Image(String),
/// macOS guest image / clone error (a message that does not originate from
/// Virtualization.framework — e.g. a path or serialization failure).
#[cfg(target_os = "macos")]
#[error("macOS image error: {0}")]
Macos(String),
/// Virtualization.framework error from the `arcbox-vz` layer.
#[cfg(target_os = "macos")]
#[error("macOS virtualization error: {0}")]
Vz(#[from] arcbox_vz::VZError),
}
impl CoreError {
/// Creates a new configuration error.
#[must_use]
pub fn config(msg: impl Into<String>) -> Self {
Self::Common(CommonError::config(msg))
}
/// Creates a new not found error.
#[must_use]
pub fn not_found(resource: impl Into<String>) -> Self {
Self::Common(CommonError::not_found(resource))
}
/// Creates a new already exists error.
#[must_use]
pub fn already_exists(resource: impl Into<String>) -> Self {
Self::Common(CommonError::already_exists(resource))
}
/// Creates a new invalid state error.
#[must_use]
pub fn invalid_state(msg: impl Into<String>) -> Self {
Self::Common(CommonError::invalid_state(msg))
}
/// Creates a new published-image registry error.
#[must_use]
pub fn image(msg: impl Into<String>) -> Self {
Self::Image(msg.into())
}
/// Creates a new macOS image error.
#[cfg(target_os = "macos")]
#[must_use]
pub fn macos(msg: impl Into<String>) -> Self {
Self::Macos(msg.into())
}
}
// Allow automatic conversion from std::io::Error to CoreError via CommonError.
impl From<std::io::Error> for CoreError {
fn from(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}