system_analysis/
error.rs

1//! Error types for the system analysis crate.
2
3use thiserror::Error;
4
5/// The main error type for the system analysis crate.
6#[derive(Error, Debug)]
7pub enum SystemAnalysisError {
8    /// Error occurred while analyzing system hardware
9    #[error("System analysis failed: {message}")]
10    AnalysisError { message: String },
11
12    /// Error occurred while accessing system information
13    #[error("System information access failed: {source}")]
14    SystemInfoError { 
15        #[source]
16        source: Box<dyn std::error::Error + Send + Sync>
17    },
18
19    /// Error occurred while calculating compatibility
20    #[error("Compatibility calculation failed: {message}")]
21    CompatibilityError { message: String },
22
23    /// Invalid workload requirements
24    #[error("Invalid workload requirements: {message}")]
25    InvalidWorkload { message: String },
26
27    /// Resource requirement not found
28    #[error("Resource requirement not found: {resource_type}")]
29    ResourceNotFound { resource_type: String },
30
31    /// Configuration error
32    #[error("Configuration error: {message}")]
33    ConfigError { message: String },
34
35    /// I/O error
36    #[error("I/O error: {0}")]
37    IoError(#[from] std::io::Error),
38
39    /// Serialization error
40    #[error("Serialization error: {0}")]
41    SerializationError(#[from] serde_json::Error),
42
43    /// GPU detection error (when feature is enabled)
44    #[cfg(feature = "gpu-detection")]
45    #[error("GPU detection error: {message}")]
46    GpuError { message: String },
47}
48
49impl SystemAnalysisError {
50    /// Create a new analysis error
51    pub fn analysis(message: impl Into<String>) -> Self {
52        Self::AnalysisError {
53            message: message.into(),
54        }
55    }
56
57    /// Create a new system info error
58    pub fn system_info(message: impl Into<String>) -> Self {
59        Self::SystemInfoError {
60            source: Box::new(std::io::Error::new(
61                std::io::ErrorKind::Other, 
62                message.into()
63            )),
64        }
65    }
66
67    /// Create a new compatibility error
68    pub fn compatibility(message: impl Into<String>) -> Self {
69        Self::CompatibilityError {
70            message: message.into(),
71        }
72    }
73
74    /// Create a new invalid workload error
75    pub fn invalid_workload(message: impl Into<String>) -> Self {
76        Self::InvalidWorkload {
77            message: message.into(),
78        }
79    }
80
81    /// Create a new resource not found error
82    pub fn resource_not_found(resource_type: impl Into<String>) -> Self {
83        Self::ResourceNotFound {
84            resource_type: resource_type.into(),
85        }
86    }
87
88    /// Create a new config error
89    pub fn config(message: impl Into<String>) -> Self {
90        Self::ConfigError {
91            message: message.into(),
92        }
93    }
94
95    #[cfg(feature = "gpu-detection")]
96    /// Create a new GPU error
97    pub fn gpu(message: impl Into<String>) -> Self {
98        Self::GpuError {
99            message: message.into(),
100        }
101    }
102}
103
104/// Convenience type alias for Results with SystemAnalysisError
105pub type Result<T> = std::result::Result<T, SystemAnalysisError>;