remove snafu

This commit is contained in:
2021-10-30 12:45:09 +02:00
parent 9e70b37820
commit fed9a73aa0
4 changed files with 37 additions and 23 deletions

View File

@ -1,30 +1,43 @@
use std::{error, io};
use std::io;
use jsonrpc_core::{types::error::Error, ErrorCode};
use probes::ProbeError;
use snafu::Snafu;
pub type BoxError = Box<dyn error::Error>;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
#[derive(Debug)]
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 std::fmt::Display for StatError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
StatError::ReadCpuStat { ref source } => {
write!(f, "Failed to retrieve CPU statistics: {}", source)
}
StatError::ReadDiskUsage { ref source } => {
write!(f, "Failed to retrieve disk usage statistics: {}", source)
}
StatError::ReadLoadAvg { ref source } => {
write!(f, "Failed to retrieve load average statistics: {}", source)
}
StatError::ReadMemStat { ref source } => {
write!(f, "Failed to retrieve memory statistics: {}", source)
}
StatError::ReadUptime { ref source } => {
write!(f, "Failed to retrieve system uptime: {}", source)
}
}
}
}
impl From<StatError> for Error {
fn from(err: StatError) -> Self {
match &err {