docker_image_pusher/
error.rs

1//! Error handling module for the Docker image pusher
2
3use std::fmt;
4
5#[derive(Debug)]
6pub enum PusherError {
7    Authentication(String),
8    Registry(String),
9    ImageParsing(String),
10    Upload(String),
11    Configuration(String),
12    Io(std::io::Error),
13    Network(reqwest::Error),
14    Serialization(serde_json::Error),
15}
16
17impl fmt::Display for PusherError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            PusherError::Authentication(msg) => write!(f, "Authentication error: {}", msg),
21            PusherError::Registry(msg) => write!(f, "Registry error: {}", msg),
22            PusherError::ImageParsing(msg) => write!(f, "Image parsing error: {}", msg),
23            PusherError::Upload(msg) => write!(f, "Upload error: {}", msg),
24            PusherError::Configuration(msg) => write!(f, "Configuration error: {}", msg),
25            PusherError::Io(err) => write!(f, "IO error: {}", err),
26            PusherError::Network(err) => write!(f, "Network error: {}", err),
27            PusherError::Serialization(err) => write!(f, "Serialization error: {}", err),
28        }
29    }
30}
31
32impl std::error::Error for PusherError {}
33
34impl From<std::io::Error> for PusherError {
35    fn from(err: std::io::Error) -> Self {
36        PusherError::Io(err)
37    }
38}
39
40impl From<reqwest::Error> for PusherError {
41    fn from(err: reqwest::Error) -> Self {
42        PusherError::Network(err)
43    }
44}
45
46impl From<serde_json::Error> for PusherError {
47    fn from(err: serde_json::Error) -> Self {
48        PusherError::Serialization(err)
49    }
50}
51
52impl From<anyhow::Error> for PusherError {
53    fn from(err: anyhow::Error) -> Self {
54        PusherError::Configuration(err.to_string())
55    }
56}
57
58pub type Result<T> = std::result::Result<T, PusherError>;