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