nerve/error/
mod.rs

1//! Error types for the Nerve Framework
2
3use thiserror::Error;
4
5/// Main error type for the Nerve Framework
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Buffer is at capacity (Guaranteed QoS only)
9    #[error("Buffer is full")]
10    BufferFull,
11
12    /// Memory allocation failed
13    #[error("Memory allocation failed: {0}")]
14    AllocationFailed(String),
15
16    /// Thread safety violation detected
17    #[error("Thread safety violation: {0}")]
18    ThreadSafety(String),
19
20    /// Buffer corruption detected
21    #[error("Buffer corruption: {0}")]
22    Corruption(String),
23
24    /// Invalid configuration
25    #[error("Invalid configuration: {0}")]
26    Config(String),
27
28    /// Generic error for unimplemented features
29    #[error("Feature not implemented: {0}")]
30    NotImplemented(String),
31
32    /// QoS policy violation
33    #[error("QoS policy violation: {0}")]
34    QosViolation(String),
35
36    /// Invalid buffer capacity
37    #[error("Invalid buffer capacity: {0}")]
38    InvalidCapacity(String),
39
40    /// Message too large for buffer
41    #[error("Message too large for buffer: {0}")]
42    MessageTooLarge(String),
43}
44
45/// Result type alias for Nerve Framework operations
46pub type Result<T> = std::result::Result<T, Error>;
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_error_display() {
54        let error: Error = Error::BufferFull;
55        assert_eq!(format!("{}", error), "Buffer is full");
56
57        let error: Error = Error::AllocationFailed("out of memory".to_string());
58        assert_eq!(format!("{}", error), "Memory allocation failed: out of memory");
59    }
60}