peach-workspace/peach-stats/src/error.rs

45 lines
1.5 KiB
Rust

//! Custom error type for `peach-stats`.
use probes::ProbeError;
use std::{error, fmt, io::Error as IoError};
/// Custom error type encapsulating all possible errors when retrieving system
/// statistics.
#[derive(Debug)]
pub enum StatsError {
/// Failed to retrieve CPU statistics.
CpuStat(ProbeError),
/// Failed to retrieve disk usage statistics.
DiskUsage(ProbeError),
/// Failed to retrieve load average statistics.
LoadAvg(ProbeError),
/// Failed to retrieve memory usage statistics.
MemStat(ProbeError),
/// Failed to retrieve system uptime.
Uptime(IoError),
}
impl error::Error for StatsError {}
impl fmt::Display for StatsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
StatsError::CpuStat(ref source) => {
write!(f, "Failed to retrieve CPU statistics: {}", source)
}
StatsError::DiskUsage(ref source) => {
write!(f, "Failed to retrieve disk usage statistics: {}", source)
}
StatsError::LoadAvg(ref source) => {
write!(f, "Failed to retrieve load average statistics: {}", source)
}
StatsError::MemStat(ref source) => {
write!(f, "Failed to retrieve memory statistics: {}", source)
}
StatsError::Uptime(ref source) => {
write!(f, "Failed to retrieve system uptime: {}", source)
}
}
}
}