Skip to main content

perfgate_server/
error.rs

1//! Error types for the perfgate server.
2
3use thiserror::Error;
4
5/// Storage-related errors.
6#[derive(Debug, Error)]
7pub enum StoreError {
8    /// Baseline already exists
9    #[error("Baseline already exists: {0}")]
10    AlreadyExists(String),
11
12    /// Baseline not found
13    #[error("Baseline not found: {0}")]
14    NotFound(String),
15
16    /// Database connection error
17    #[error("Database connection error: {0}")]
18    ConnectionError(String),
19
20    /// Query execution error
21    #[error("Query error: {0}")]
22    QueryError(String),
23
24    /// Serialization error
25    #[error("Serialization error: {0}")]
26    SerializationError(#[from] serde_json::Error),
27
28    /// IO error
29    #[error("IO error: {0}")]
30    IoError(#[from] std::io::Error),
31
32    /// SQLite error
33    #[error("SQLite error: {0}")]
34    SqliteError(#[from] rusqlite::Error),
35
36    /// Lock error
37    #[error("Lock error: {0}")]
38    LockError(String),
39
40    /// Generic error
41    #[error("{0}")]
42    Other(String),
43}
44
45impl StoreError {
46    /// Creates a new "already exists" error.
47    pub fn already_exists(project: &str, benchmark: &str, version: &str) -> Self {
48        Self::AlreadyExists(format!(
49            "project={}, benchmark={}, version={}",
50            project, benchmark, version
51        ))
52    }
53
54    /// Creates a new "not found" error.
55    pub fn not_found(project: &str, benchmark: &str, version: &str) -> Self {
56        Self::NotFound(format!(
57            "project={}, benchmark={}, version={}",
58            project, benchmark, version
59        ))
60    }
61}
62
63/// Authentication-related errors.
64#[derive(Debug, Error)]
65pub enum AuthError {
66    /// Missing authentication header
67    #[error("Missing authentication header")]
68    MissingAuth,
69
70    /// Invalid API key format
71    #[error("Invalid API key format")]
72    InvalidKeyFormat,
73
74    /// Invalid API key
75    #[error("Invalid API key")]
76    InvalidKey,
77
78    /// Expired API key
79    #[error("API key has expired")]
80    ExpiredKey,
81
82    /// Invalid JWT token
83    #[error("Invalid JWT token: {0}")]
84    InvalidToken(String),
85
86    /// Expired JWT token
87    #[error("JWT token has expired")]
88    ExpiredToken,
89
90    /// Insufficient permissions
91    #[error("Insufficient permissions: required {required}, has {actual}")]
92    InsufficientPermissions { required: String, actual: String },
93}
94
95/// Server configuration errors.
96#[derive(Debug, Error)]
97pub enum ConfigError {
98    /// Invalid configuration value
99    #[error("Invalid configuration: {0}")]
100    InvalidValue(String),
101
102    /// Missing required configuration
103    #[error("Missing required configuration: {0}")]
104    MissingRequired(String),
105
106    /// File I/O error
107    #[error("Configuration file error: {0}")]
108    FileError(#[from] std::io::Error),
109
110    /// Parse error
111    #[error("Configuration parse error: {0}")]
112    ParseError(String),
113}