Skip to main content

ferro_deployments/
error.rs

1//! Error types for the deployments system.
2
3use thiserror::Error;
4
5/// Errors that can occur in the deployments system.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Database error.
9    #[error("Database error: {0}")]
10    Db(#[from] sea_orm::DbErr),
11
12    /// Unsupported database backend.
13    #[error("Unsupported database backend")]
14    UnsupportedBackend,
15
16    /// JSON error.
17    #[error("JSON error: {0}")]
18    Json(#[from] serde_json::Error),
19
20    /// Deployment is not in the ready state and cannot be promoted.
21    #[error("Deployment {id} cannot be promoted: status is not ready")]
22    NotReady {
23        /// The deployment ID.
24        id: i64,
25    },
26
27    /// Deployment artifacts have been deleted; promotion refused.
28    #[error("Deployment {id} cannot be promoted: artifact has been deleted")]
29    ArtifactDeleted {
30        /// The deployment ID.
31        id: i64,
32    },
33
34    /// No previous deployment exists for rollback.
35    #[error("No previous deployment to roll back to for owner_key '{owner_key}'")]
36    NoPreviousDeployment {
37        /// The owner key.
38        owner_key: String,
39    },
40
41    /// Deployment not found.
42    #[error("Deployment {id} not found")]
43    NotFound {
44        /// The deployment ID.
45        id: i64,
46    },
47
48    /// Storage error.
49    #[error("Storage error: {0}")]
50    Storage(#[from] ferro_storage::Error),
51
52    /// Custom error.
53    #[error("{0}")]
54    Custom(String),
55}
56
57impl Error {
58    /// Create a custom error.
59    pub fn custom(message: impl Into<String>) -> Self {
60        Self::Custom(message.into())
61    }
62}
63
64impl From<String> for Error {
65    fn from(s: String) -> Self {
66        Self::Custom(s)
67    }
68}
69
70impl From<&str> for Error {
71    fn from(s: &str) -> Self {
72        Self::Custom(s.to_string())
73    }
74}