Skip to main content

haagenti_adaptive/
error.rs

1//! Error types for adaptive precision
2
3use thiserror::Error;
4
5/// Errors that can occur during adaptive precision operations
6#[derive(Debug, Error)]
7pub enum AdaptiveError {
8    /// Invalid step number
9    #[error("Invalid step {step}: must be in range [0, {total_steps})")]
10    InvalidStep { step: u32, total_steps: u32 },
11
12    /// Invalid precision transition
13    #[error("Invalid transition from {from:?} to {to:?}: {reason}")]
14    InvalidTransition {
15        from: crate::Precision,
16        to: crate::Precision,
17        reason: String,
18    },
19
20    /// Precision not supported by hardware
21    #[error("Precision {0:?} not supported by hardware")]
22    UnsupportedPrecision(crate::Precision),
23
24    /// Profile configuration error
25    #[error("Profile error: {0}")]
26    ProfileError(String),
27
28    /// Schedule generation failed
29    #[error("Failed to generate schedule: {0}")]
30    ScheduleError(String),
31
32    /// VRAM constraint violation
33    #[error("VRAM constraint violated: required {required_mb}MB, available {available_mb}MB")]
34    VramConstraint { required_mb: u64, available_mb: u64 },
35
36    /// Quality constraint violation
37    #[error("Quality below threshold: {actual:.3} < {threshold:.3}")]
38    QualityConstraint { actual: f32, threshold: f32 },
39}
40
41/// Result type for adaptive precision operations
42pub type Result<T> = std::result::Result<T, AdaptiveError>;
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_error_display() {
50        let err = AdaptiveError::InvalidStep {
51            step: 50,
52            total_steps: 30,
53        };
54        assert!(err.to_string().contains("50"));
55        assert!(err.to_string().contains("30"));
56    }
57}