1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

util/error: init

This commit is contained in:
Bloxx12 2025-05-13 20:02:09 +02:00
parent e6015cf0f1
commit 7d6164c2fe
No known key found for this signature in database
6 changed files with 81 additions and 73 deletions

View file

@ -1,5 +1,7 @@
use crate::config::AppConfig;
use crate::core::{BatteryInfo, CpuCoreInfo, CpuGlobalInfo, SystemInfo, SystemLoad, SystemReport};
use crate::util::error::ControlError;
use crate::util::error::SysMonitorError;
use std::{
collections::HashMap,
fs, io,
@ -10,35 +12,6 @@ use std::{
time::SystemTime,
};
#[derive(Debug)]
pub enum SysMonitorError {
Io(io::Error),
ReadError(String),
ParseError(String),
ProcStatParseError(String),
NotAvailable(String),
}
impl From<io::Error> for SysMonitorError {
fn from(err: io::Error) -> Self {
Self::Io(err)
}
}
impl std::fmt::Display for SysMonitorError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(e) => write!(f, "I/O error: {e}"),
Self::ReadError(s) => write!(f, "Failed to read sysfs path: {s}"),
Self::ParseError(s) => write!(f, "Failed to parse value: {s}"),
Self::ProcStatParseError(s) => {
write!(f, "Failed to parse /proc/stat: {s}")
}
Self::NotAvailable(s) => write!(f, "Information not available: {s}"),
}
}
}
impl std::error::Error for SysMonitorError {}
pub type Result<T, E = SysMonitorError> = std::result::Result<T, E>;