Skip to main content

perfgate_server/
error.rs

1//! Error types for the perfgate server.
2
3pub use perfgate_error::AuthError;
4use thiserror::Error;
5
6/// Storage-related errors.
7#[derive(Debug, Error)]
8pub enum StoreError {
9    /// Baseline already exists
10    #[error("Baseline already exists: {0}")]
11    AlreadyExists(String),
12
13    /// Baseline not found
14    #[error("Baseline not found: {0}")]
15    NotFound(String),
16
17    /// Database connection error
18    #[error("Database connection error: {0}")]
19    ConnectionError(String),
20
21    /// Query execution error
22    #[error("Query error: {0}")]
23    QueryError(String),
24
25    /// Serialization error
26    #[error("Serialization error: {0}")]
27    SerializationError(#[from] serde_json::Error),
28
29    /// IO error
30    #[error("IO error: {0}")]
31    IoError(#[from] std::io::Error),
32
33    /// SQLite error
34    #[error("SQLite error: {0}")]
35    SqliteError(#[from] rusqlite::Error),
36
37    /// Lock error
38    #[error("Lock error: {0}")]
39    LockError(String),
40
41    /// Generic error
42    #[error("{0}")]
43    Other(String),
44}
45
46impl StoreError {
47    /// Creates a new "already exists" error.
48    pub fn already_exists(project: &str, benchmark: &str, version: &str) -> Self {
49        Self::AlreadyExists(format!(
50            "project={}, benchmark={}, version={}",
51            project, benchmark, version
52        ))
53    }
54
55    /// Creates a new "not found" error.
56    pub fn not_found(project: &str, benchmark: &str, version: &str) -> Self {
57        Self::NotFound(format!(
58            "project={}, benchmark={}, version={}",
59            project, benchmark, version
60        ))
61    }
62}
63
64/// Server configuration errors.
65#[derive(Debug, Error)]
66pub enum ConfigError {
67    /// Invalid configuration value
68    #[error("Invalid configuration: {0}")]
69    InvalidValue(String),
70
71    /// Missing required configuration
72    #[error("Missing required configuration: {0}")]
73    MissingRequired(String),
74
75    /// File I/O error
76    #[error("Configuration file error: {0}")]
77    FileError(#[from] std::io::Error),
78
79    /// Parse error
80    #[error("Configuration parse error: {0}")]
81    ParseError(String),
82}