Skip to main content

cortexai_audit/
error.rs

1//! Error types for the audit module.
2
3use thiserror::Error;
4
5/// Errors that can occur during audit operations.
6#[derive(Debug, Error)]
7pub enum AuditError {
8    /// I/O error during file operations
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// Serialization error
13    #[error("Serialization error: {0}")]
14    Serialization(#[from] serde_json::Error),
15
16    /// Configuration error
17    #[error("Configuration error: {0}")]
18    Config(String),
19
20    /// Buffer full error
21    #[error("Audit buffer full, events may be dropped")]
22    BufferFull,
23
24    /// Logger not initialized
25    #[error("Audit logger not initialized")]
26    NotInitialized,
27
28    /// Multiple errors from composite logger
29    #[error("Multiple errors: {0:?}")]
30    Multiple(Vec<String>),
31
32    /// Rotation error
33    #[error("Log rotation error: {0}")]
34    Rotation(String),
35
36    /// Channel send error
37    #[error("Channel send error")]
38    ChannelSend,
39
40    /// Shutdown error
41    #[error("Logger shutdown error: {0}")]
42    Shutdown(String),
43
44    /// Generic internal error
45    #[error("Internal error: {0}")]
46    Internal(String),
47}
48
49impl AuditError {
50    /// Create a configuration error.
51    pub fn config(msg: impl Into<String>) -> Self {
52        Self::Config(msg.into())
53    }
54
55    /// Create a rotation error.
56    pub fn rotation(msg: impl Into<String>) -> Self {
57        Self::Rotation(msg.into())
58    }
59
60    /// Create an internal error.
61    pub fn internal(msg: impl Into<String>) -> Self {
62        Self::Internal(msg.into())
63    }
64}