mockforge_analytics/
error.rs

1//! Error types for the analytics module
2
3use thiserror::Error;
4
5/// Result type for analytics operations
6pub type Result<T> = std::result::Result<T, AnalyticsError>;
7
8/// Error types for analytics operations
9#[derive(Debug, Error)]
10pub enum AnalyticsError {
11    /// Database error
12    #[error("Database error: {0}")]
13    Database(#[from] sqlx::Error),
14
15    /// Migration error
16    #[error("Migration error: {0}")]
17    Migration(String),
18
19    /// Serialization error
20    #[error("Serialization error: {0}")]
21    Serialization(#[from] serde_json::Error),
22
23    /// HTTP error (when querying Prometheus)
24    #[error("HTTP error: {0}")]
25    Http(#[from] reqwest::Error),
26
27    /// Invalid configuration
28    #[error("Invalid configuration: {0}")]
29    InvalidConfig(String),
30
31    /// Query error
32    #[error("Query error: {0}")]
33    Query(String),
34
35    /// Export error
36    #[error("Export error: {0}")]
37    Export(String),
38
39    /// IO error
40    #[error("IO error: {0}")]
41    Io(#[from] std::io::Error),
42
43    /// Generic error
44    #[error("{0}")]
45    Other(String),
46}
47
48impl From<String> for AnalyticsError {
49    fn from(s: String) -> Self {
50        AnalyticsError::Other(s)
51    }
52}
53
54impl From<&str> for AnalyticsError {
55    fn from(s: &str) -> Self {
56        AnalyticsError::Other(s.to_string())
57    }
58}