use std::{error, io}; use jsonrpc_core::{types::error::Error, ErrorCode}; use probes::ProbeError; use snafu::Snafu; pub type BoxError = Box; #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] pub enum StatError { #[snafu(display("Failed to retrieve CPU statistics: {}", source))] ReadCpuStat { source: ProbeError }, #[snafu(display("Failed to retrieve disk usage statistics: {}", source))] ReadDiskUsage { source: ProbeError }, #[snafu(display("Failed to retrieve load average statistics: {}", source))] ReadLoadAvg { source: ProbeError }, #[snafu(display("Failed to retrieve memory statistics: {}", source))] ReadMemStat { source: ProbeError }, #[snafu(display("Failed to retrieve system uptime: {}", source))] ReadUptime { source: io::Error }, } impl From for Error { fn from(err: StatError) -> Self { match &err { StatError::ReadCpuStat { source } => Error { code: ErrorCode::ServerError(-32001), message: format!("Failed to retrieve CPU statistics: {}", source), data: None, }, StatError::ReadDiskUsage { source } => Error { code: ErrorCode::ServerError(-32001), message: format!("Failed to retrieve disk usage statistics: {}", source), data: None, }, StatError::ReadLoadAvg { source } => Error { code: ErrorCode::ServerError(-32001), message: format!("Failed to retrieve load average statistics: {}", source), data: None, }, StatError::ReadMemStat { source } => Error { code: ErrorCode::ServerError(-32001), message: format!("Failed to retrieve memory statistics: {}", source), data: None, }, StatError::ReadUptime { source } => Error { code: ErrorCode::ServerError(-32001), message: format!("Failed to retrieve system uptime: {}", source), data: None, }, } } }