hardware_query/
error.rs

1/// Result type for hardware query operations
2pub type Result<T> = std::result::Result<T, HardwareQueryError>;
3
4/// Error types that can occur during hardware querying
5#[derive(Debug, thiserror::Error)]
6pub enum HardwareQueryError {
7    /// System information is not available
8    #[error("System information not available: {0}")]
9    SystemInfoUnavailable(String),
10
11    /// Hardware device not found
12    #[error("Hardware device not found: {0}")]
13    DeviceNotFound(String),
14
15    /// Platform not supported
16    #[error("Platform not supported: {0}")]
17    PlatformNotSupported(String),
18
19    /// Permission denied accessing hardware information
20    #[error("Permission denied: {0}")]
21    PermissionDenied(String),
22
23    /// I/O error occurred
24    #[error("I/O error: {0}")]
25    IoError(#[from] std::io::Error),
26
27    /// Serialization error
28    #[error("Serialization error: {0}")]
29    SerializationError(#[from] serde_json::Error),
30
31    /// WMI error (Windows only)
32    #[cfg(target_os = "windows")]
33    #[error("WMI error: {0}")]
34    WMIError(#[from] wmi::WMIError),
35
36    /// GPU driver error
37    #[error("GPU driver error: {0}")]
38    GPUDriverError(String),
39
40    /// Invalid hardware configuration
41    #[error("Invalid hardware configuration: {0}")]
42    InvalidConfiguration(String),
43
44    /// Monitoring error
45    #[error("Monitoring error: {0}")]
46    MonitoringError(String),
47
48    /// Power management error
49    #[error("Power management error: {0}")]
50    PowerManagementError(String),
51
52    /// Virtualization detection error
53    #[error("Virtualization detection error: {0}")]
54    VirtualizationError(String),
55
56    /// Thermal management error
57    #[error("Thermal management error: {0}")]
58    ThermalError(String),
59
60    /// Unknown error
61    #[error("Unknown error: {0}")]
62    Unknown(String),
63}
64
65impl HardwareQueryError {
66    pub fn system_info_unavailable(msg: impl Into<String>) -> Self {
67        Self::SystemInfoUnavailable(msg.into())
68    }
69
70    pub fn device_not_found(msg: impl Into<String>) -> Self {
71        Self::DeviceNotFound(msg.into())
72    }
73
74    pub fn platform_not_supported(msg: impl Into<String>) -> Self {
75        Self::PlatformNotSupported(msg.into())
76    }
77
78    pub fn permission_denied(msg: impl Into<String>) -> Self {
79        Self::PermissionDenied(msg.into())
80    }
81
82    pub fn gpu_driver_error(msg: impl Into<String>) -> Self {
83        Self::GPUDriverError(msg.into())
84    }
85
86    pub fn invalid_configuration(msg: impl Into<String>) -> Self {
87        Self::InvalidConfiguration(msg.into())
88    }
89
90    pub fn monitoring_error(msg: impl Into<String>) -> Self {
91        Self::MonitoringError(msg.into())
92    }
93
94    pub fn power_management_error(msg: impl Into<String>) -> Self {
95        Self::PowerManagementError(msg.into())
96    }
97
98    pub fn virtualization_error(msg: impl Into<String>) -> Self {
99        Self::VirtualizationError(msg.into())
100    }
101
102    pub fn thermal_error(msg: impl Into<String>) -> Self {
103        Self::ThermalError(msg.into())
104    }
105
106    pub fn unknown(msg: impl Into<String>) -> Self {
107        Self::Unknown(msg.into())
108    }
109}