entrenar/storage/cloud/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum CloudError {
8 #[error("IO error: {0}")]
9 Io(#[from] std::io::Error),
10
11 #[error("Artifact not found: {0}")]
12 NotFound(String),
13
14 #[error("Backend error: {0}")]
15 Backend(String),
16
17 #[error("Configuration error: {0}")]
18 Config(String),
19
20 #[error("Permission denied: {0}")]
21 PermissionDenied(String),
22
23 #[error("Network error: {0}")]
24 Network(String),
25}
26
27pub type Result<T> = std::result::Result<T, CloudError>;
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn test_cloud_error_display() {
36 let io_err =
37 CloudError::Io(std::io::Error::new(std::io::ErrorKind::NotFound, "file not found"));
38 assert!(io_err.to_string().contains("IO error"));
39
40 let not_found = CloudError::NotFound("abc123".to_string());
41 assert!(not_found.to_string().contains("abc123"));
42
43 let backend = CloudError::Backend("connection failed".to_string());
44 assert!(backend.to_string().contains("connection failed"));
45
46 let config = CloudError::Config("invalid config".to_string());
47 assert!(config.to_string().contains("invalid config"));
48
49 let permission = CloudError::PermissionDenied("access denied".to_string());
50 assert!(permission.to_string().contains("access denied"));
51
52 let network = CloudError::Network("timeout".to_string());
53 assert!(network.to_string().contains("timeout"));
54 }
55}