Skip to main content

cpufetch_rs/
error.rs

1//! Error types for cpufetch
2//!
3//! This module provides the error types used throughout the crate.
4
5use thiserror::Error;
6
7/// Main error type for cpufetch operations
8#[derive(Debug, Error)]
9pub enum Error {
10    #[error("CPU detection error: {0}")]
11    CpuDetection(String),
12
13    #[error("CPU error: {0}")]
14    Cpu(#[from] crate::cpu::info::CpuError),
15
16    #[error("Feature detection error: {0}")]
17    Feature(#[from] crate::cpu::flags::FeatureError),
18
19    #[error("I/O error: {0}")]
20    Io(#[from] std::io::Error),
21
22    #[error("Unsupported architecture")]
23    UnsupportedArchitecture,
24
25    // Feature-specific errors
26    #[cfg(feature = "frequency")]
27    #[error("Frequency detection error: {0}")]
28    Frequency(String),
29
30    #[cfg(feature = "display")]
31    #[error("Display error: {0}")]
32    Display(String),
33
34    #[cfg(feature = "json")]
35    #[error("JSON serialization error: {0}")]
36    Json(#[from] serde_json::Error),
37
38    #[cfg(feature = "config")]
39    #[error("Configuration error: {0}")]
40    Config(String),
41
42    #[cfg(feature = "cli")]
43    #[error("CLI error: {0}")]
44    Cli(String),
45
46    #[error("Unknown error: {0}")]
47    Other(String),
48}
49
50/// Create a basic implementation for conversion from string errors
51impl From<String> for Error {
52    fn from(err: String) -> Self {
53        Error::Other(err)
54    }
55}
56
57/// Create a basic implementation for conversion from static string errors
58impl From<&str> for Error {
59    fn from(err: &str) -> Self {
60        Error::Other(err.to_string())
61    }
62}