docker_image_pusher/error/
mod.rs1pub mod handlers;
4
5use std::fmt;
6
7pub type Result<T> = std::result::Result<T, RegistryError>;
8
9#[derive(Debug, Clone)]
10pub enum RegistryError {
11 Network(String),
13 Registry(String),
15 Auth(String),
17 Io(String),
19 Parse(String),
21 ImageParsing(String),
23 Upload(String),
25 Http(String),
27 Validation(String),
29 Cache {
31 message: String,
32 path: Option<std::path::PathBuf>,
33 },
34 NotFound(String),
36}
37
38impl fmt::Display for RegistryError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 RegistryError::Network(msg) => write!(f, "Network error: {}", msg),
42 RegistryError::Registry(msg) => write!(f, "Registry error: {}", msg),
43 RegistryError::Auth(msg) => write!(f, "Authentication error: {}", msg),
44 RegistryError::Io(msg) => write!(f, "IO error: {}", msg),
45 RegistryError::Parse(msg) => write!(f, "Parse error: {}", msg),
46 RegistryError::ImageParsing(msg) => write!(f, "Image parsing error: {}", msg),
47 RegistryError::Upload(msg) => write!(f, "Upload error: {}", msg),
48 RegistryError::Http(msg) => write!(f, "HTTP error: {}", msg),
49 RegistryError::Validation(msg) => write!(f, "Validation error: {}", msg),
50 RegistryError::Cache { message, path } => {
51 if let Some(path) = path {
52 write!(f, "Cache error at {}: {}", path.display(), message)
53 } else {
54 write!(f, "Cache error: {}", message)
55 }
56 }
57 RegistryError::NotFound(msg) => write!(f, "Not found: {}", msg),
58 }
59 }
60}
61
62impl std::error::Error for RegistryError {}
63
64impl From<std::io::Error> for RegistryError {
65 fn from(err: std::io::Error) -> Self {
66 RegistryError::Io(err.to_string())
67 }
68}
69
70impl From<serde_json::Error> for RegistryError {
71 fn from(err: serde_json::Error) -> Self {
72 RegistryError::Parse(err.to_string())
73 }
74}
75
76impl From<reqwest::Error> for RegistryError {
77 fn from(err: reqwest::Error) -> Self {
78 RegistryError::Network(err.to_string())
79 }
80}
81
82impl From<url::ParseError> for RegistryError {
83 fn from(err: url::ParseError) -> Self {
84 RegistryError::Validation(err.to_string())
85 }
86}
87
88impl From<std::string::FromUtf8Error> for RegistryError {
89 fn from(err: std::string::FromUtf8Error) -> Self {
90 RegistryError::Parse(format!("UTF-8 conversion error: {}", err))
91 }
92}