Skip to main content

cbtop/
error.rs

1//! Error types for cbtop
2//!
3//! # Yuan Gate Error Handling
4//!
5//! Reference: Yuan, D., et al. (2014). "Simple Testing Can Prevent Most Critical Failures"
6//! - 92% of catastrophic failures caused by `_ => {}` catch-all patterns
7//! - All errors are explicit, no catch-all patterns allowed
8
9use thiserror::Error;
10
11/// Main error type for cbtop
12#[derive(Error, Debug)]
13pub enum CbtopError {
14    /// Terminal I/O error
15    #[error("Terminal error: {0}")]
16    Terminal(#[from] std::io::Error),
17
18    /// Configuration error
19    #[error("Configuration error: {0}")]
20    Config(String),
21
22    /// File I/O error (string message)
23    #[error("I/O error: {0}")]
24    Io(String),
25
26    /// Brick verification failed
27    #[error("Brick verification failed: {brick_name} - {reason}")]
28    BrickVerification { brick_name: String, reason: String },
29
30    /// Collector error
31    #[error("Collector error: {0}")]
32    Collector(#[from] CollectorError),
33
34    /// Load generator error
35    #[error("Load generator error: {0}")]
36    LoadGenerator(#[from] LoadError),
37
38    /// No GPU available
39    #[error("No GPU available")]
40    NoGpu,
41
42    /// Invalid device index
43    #[error("Invalid device index: {0}")]
44    InvalidDevice(u32),
45
46    /// Budget exceeded
47    #[error("Budget exceeded: {phase} took {elapsed_ms}ms (budget: {budget_ms}ms)")]
48    BudgetExceeded {
49        phase: String,
50        elapsed_ms: u64,
51        budget_ms: u32,
52    },
53
54    /// Render error
55    #[error("Render error: {0}")]
56    Render(String),
57}
58
59/// Collector-specific errors
60#[derive(Error, Debug)]
61pub enum CollectorError {
62    /// Failed to read /proc filesystem
63    #[error("Failed to read /proc: {0}")]
64    ProcFs(String),
65
66    /// Failed to read sysfs
67    #[error("Failed to read sysfs: {0}")]
68    SysFs(String),
69
70    /// NVML error
71    #[error("NVML error: {0}")]
72    Nvml(String),
73
74    /// wgpu error
75    #[error("wgpu error: {0}")]
76    Wgpu(String),
77
78    /// Data source not available
79    #[error("Data source not available: {0}")]
80    NotAvailable(String),
81
82    /// Parse error
83    #[error("Parse error: {0}")]
84    Parse(String),
85}
86
87/// Load generator errors
88#[derive(Error, Debug)]
89pub enum LoadError {
90    /// Backend not available
91    #[error("Backend not available: {0}")]
92    BackendNotAvailable(String),
93
94    /// Allocation failed
95    #[error("Allocation failed: {0}")]
96    AllocationFailed(String),
97
98    /// Kernel launch failed
99    #[error("Kernel launch failed: {0}")]
100    KernelLaunchFailed(String),
101
102    /// Synchronization failed
103    #[error("Synchronization failed: {0}")]
104    SyncFailed(String),
105
106    /// Invalid configuration
107    #[error("Invalid configuration: {0}")]
108    InvalidConfig(String),
109}
110
111/// Result type alias for cbtop
112pub type Result<T> = std::result::Result<T, CbtopError>;