Skip to main content

cbtop/grammar/
error.rs

1//! Error types for grammar operations.
2
3use std::time::Duration;
4
5/// Result type for grammar operations
6pub type GrammarResult<T> = Result<T, GrammarError>;
7
8/// Error types for grammar operations
9#[derive(Debug, Clone, PartialEq)]
10pub enum GrammarError {
11    /// Missing required workload specification
12    MissingWorkload,
13    /// Invalid dimensions (zero or negative)
14    InvalidDimensions(String),
15    /// Invalid scale domain (min >= max)
16    InvalidScaleDomain { min: f64, max: f64 },
17    /// Device not found
18    DeviceNotFound(u32),
19    /// Execution timeout
20    Timeout(Duration),
21    /// Strategy not supported on current hardware
22    UnsupportedStrategy(String),
23    /// Validation error
24    ValidationError(String),
25    /// Execution error
26    ExecutionError(String),
27}
28
29impl std::fmt::Display for GrammarError {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        match self {
32            GrammarError::MissingWorkload => write!(f, "Missing required workload specification"),
33            GrammarError::InvalidDimensions(msg) => write!(f, "Invalid dimensions: {}", msg),
34            GrammarError::InvalidScaleDomain { min, max } => {
35                write!(f, "Invalid scale domain: min {} >= max {}", min, max)
36            }
37            GrammarError::DeviceNotFound(id) => write!(f, "Device {} not found", id),
38            GrammarError::Timeout(d) => write!(f, "Execution timeout after {:?}", d),
39            GrammarError::UnsupportedStrategy(s) => write!(f, "Unsupported strategy: {}", s),
40            GrammarError::ValidationError(s) => write!(f, "Validation error: {}", s),
41            GrammarError::ExecutionError(s) => write!(f, "Execution error: {}", s),
42        }
43    }
44}
45
46impl std::error::Error for GrammarError {}