hyprstream_workers/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum WorkerError {
8 #[error("Sandbox not found: {0}")]
12 SandboxNotFound(String),
13
14 #[error("Sandbox creation failed: {0}")]
15 SandboxCreationFailed(String),
16
17 #[error("Sandbox already exists: {0}")]
18 SandboxAlreadyExists(String),
19
20 #[error(
21 "Sandbox in invalid state for operation: {sandbox_id} is {state}, expected {expected}"
22 )]
23 SandboxInvalidState {
24 sandbox_id: String,
25 state: String,
26 expected: String,
27 },
28
29 #[error("Sandbox pool exhausted: max {max} sandboxes")]
30 PoolExhausted { max: usize },
31
32 #[error("Sandbox timeout: {operation} took longer than {timeout_secs}s")]
33 SandboxTimeout {
34 operation: String,
35 timeout_secs: u64,
36 },
37
38 #[error("Admission denied: {reason}")]
45 AdmissionDenied { reason: String },
46
47 #[error("Admission queue full: {waiting} waiting (bound {bound})")]
51 QueueFull { waiting: usize, bound: usize },
52
53 #[error("Admission queue wait timed out after {timeout_secs}s")]
56 QueueTimeout { timeout_secs: u64 },
57
58 #[error("Admission infeasible: {reason}")]
64 AdmissionInfeasible { reason: String },
65
66 #[error("VM start failed: {0}")]
70 VmStartFailed(String),
71
72 #[error("VM stop failed: {0}")]
73 VmStopFailed(String),
74
75 #[error("Cloud-init generation failed: {0}")]
76 CloudInitFailed(String),
77
78 #[error("VirtioFS daemon failed: {0}")]
79 VirtiofsFailed(String),
80
81 #[error("Container not found: {0}")]
85 ContainerNotFound(String),
86
87 #[error("Container creation failed: {0}")]
88 ContainerCreationFailed(String),
89
90 #[error("Container already exists: {0}")]
91 ContainerAlreadyExists(String),
92
93 #[error("Container in invalid state: {container_id} is {state}, expected {expected}")]
94 ContainerInvalidState {
95 container_id: String,
96 state: String,
97 expected: String,
98 },
99
100 #[error("Container exec failed: {0}")]
101 ExecFailed(String),
102
103 #[error("Image not found: {0}")]
107 ImageNotFound(String),
108
109 #[error("Failed to pull image {image}: {reason}")]
110 ImagePullFailed { image: String, reason: String },
111
112 #[error("Failed to parse image reference {image}: {reason}")]
113 ImageParseFailed { image: String, reason: String },
114
115 #[error("Image invalid: {0}")]
116 ImageInvalid(String),
117
118 #[error("Registry authentication failed: {0}")]
119 RegistryAuthFailed(String),
120
121 #[error("RAFS store error: {0}")]
122 RafsError(String),
123
124 #[error("Workflow not found: {0}")]
128 WorkflowNotFound(String),
129
130 #[error("Workflow parse error: {0}")]
131 WorkflowParseError(String),
132
133 #[error("Workflow run not found: {0}")]
134 RunNotFound(String),
135
136 #[error("Workflow dispatch failed: {0}")]
137 DispatchFailed(String),
138
139 #[error("Workflow step failed: job={job}, step={step}, error={error}")]
140 StepFailed {
141 job: String,
142 step: String,
143 error: String,
144 },
145
146 #[error("Workflow timeout: {workflow_id} exceeded {timeout_secs}s")]
147 WorkflowTimeout {
148 workflow_id: String,
149 timeout_secs: u64,
150 },
151
152 #[error("Event subscription failed: {0}")]
156 SubscriptionFailed(String),
157
158 #[error("Event publish failed: {0}")]
159 PublishFailed(String),
160
161 #[error("Invalid event topic: {0}")]
162 InvalidTopic(String),
163
164 #[error("Unauthorized: {subject} cannot {operation} on {resource}")]
168 Unauthorized {
169 subject: String,
170 operation: String,
171 resource: String,
172 },
173
174 #[error("Policy check failed: {0}")]
175 PolicyError(String),
176
177 #[error("Transport error: {0}")]
181 TransportError(String),
182
183 #[error("Serialization error: {0}")]
184 SerializationError(String),
185
186 #[error("IO error: {0}")]
187 IoError(String),
188
189 #[error("Configuration error: {0}")]
190 ConfigError(String),
191
192 #[error("Internal error: {0}")]
193 Internal(String),
194
195 #[error("Unsupported operation: {0}")]
203 Unsupported(String),
204}
205
206impl From<anyhow::Error> for WorkerError {
207 fn from(err: anyhow::Error) -> Self {
208 WorkerError::Internal(err.to_string())
209 }
210}
211
212impl From<serde_json::Error> for WorkerError {
213 fn from(err: serde_json::Error) -> Self {
214 WorkerError::SerializationError(err.to_string())
215 }
216}
217
218impl From<serde_yaml::Error> for WorkerError {
219 fn from(err: serde_yaml::Error) -> Self {
220 WorkerError::SerializationError(err.to_string())
221 }
222}
223
224impl From<capnp::Error> for WorkerError {
225 fn from(err: capnp::Error) -> Self {
226 WorkerError::SerializationError(err.to_string())
227 }
228}
229
230impl From<std::io::Error> for WorkerError {
231 fn from(err: std::io::Error) -> Self {
232 WorkerError::IoError(err.to_string())
233 }
234}
235
236pub type Result<T> = std::result::Result<T, WorkerError>;
238
239#[cfg(test)]
240mod tests {
241 use super::*;
242
243 #[test]
244 fn test_error_display() {
245 let err = WorkerError::SandboxNotFound("abc123".to_owned());
246 assert_eq!(err.to_string(), "Sandbox not found: abc123");
247
248 let err = WorkerError::Unauthorized {
249 subject: "anonymous".to_owned(),
250 operation: "execute".to_owned(),
251 resource: "sandbox:*".to_owned(),
252 };
253 assert!(err.to_string().contains("anonymous"));
254 assert!(err.to_string().contains("execute"));
255 }
256}