remove redundant error variant prefixes

This commit is contained in:
2021-11-01 14:10:16 +02:00
parent dc4fdb37e8
commit 59ad6f2523
2 changed files with 26 additions and 24 deletions

View File

@ -1,33 +1,35 @@
use std::io;
use std::{error, fmt, io};
use jsonrpc_core::{types::error::Error, ErrorCode};
use probes::ProbeError;
#[derive(Debug)]
pub enum StatError {
ReadCpuStat { source: ProbeError },
ReadDiskUsage { source: ProbeError },
ReadLoadAvg { source: ProbeError },
ReadMemStat { source: ProbeError },
ReadUptime { source: io::Error },
CpuStat { source: ProbeError },
DiskUsage { source: ProbeError },
LoadAvg { source: ProbeError },
MemStat { source: ProbeError },
Uptime { source: io::Error },
}
impl std::fmt::Display for StatError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl error::Error for StatError {}
impl fmt::Display for StatError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
StatError::ReadCpuStat { ref source } => {
StatError::CpuStat { ref source } => {
write!(f, "Failed to retrieve CPU statistics: {}", source)
}
StatError::ReadDiskUsage { ref source } => {
StatError::DiskUsage { ref source } => {
write!(f, "Failed to retrieve disk usage statistics: {}", source)
}
StatError::ReadLoadAvg { ref source } => {
StatError::LoadAvg { ref source } => {
write!(f, "Failed to retrieve load average statistics: {}", source)
}
StatError::ReadMemStat { ref source } => {
StatError::MemStat { ref source } => {
write!(f, "Failed to retrieve memory statistics: {}", source)
}
StatError::ReadUptime { ref source } => {
StatError::Uptime { ref source } => {
write!(f, "Failed to retrieve system uptime: {}", source)
}
}
@ -37,27 +39,27 @@ impl std::fmt::Display for StatError {
impl From<StatError> for Error {
fn from(err: StatError) -> Self {
match &err {
StatError::ReadCpuStat { source } => Error {
StatError::CpuStat { source } => Error {
code: ErrorCode::ServerError(-32001),
message: format!("Failed to retrieve CPU statistics: {}", source),
data: None,
},
StatError::ReadDiskUsage { source } => Error {
StatError::DiskUsage { source } => Error {
code: ErrorCode::ServerError(-32001),
message: format!("Failed to retrieve disk usage statistics: {}", source),
data: None,
},
StatError::ReadLoadAvg { source } => Error {
StatError::LoadAvg { source } => Error {
code: ErrorCode::ServerError(-32001),
message: format!("Failed to retrieve load average statistics: {}", source),
data: None,
},
StatError::ReadMemStat { source } => Error {
StatError::MemStat { source } => Error {
code: ErrorCode::ServerError(-32001),
message: format!("Failed to retrieve memory statistics: {}", source),
data: None,
},
StatError::ReadUptime { source } => Error {
StatError::Uptime { source } => Error {
code: ErrorCode::ServerError(-32001),
message: format!("Failed to retrieve system uptime: {}", source),
data: None,