use crate::msg::StatusCode;
use std::fmt;
#[derive(Debug)]
pub enum MotorcortexError {
Connection(String),
Encode(String),
Decode(String),
ParameterNotFound(String),
Status(StatusCode),
Io(String),
Subscription(String),
}
impl fmt::Display for MotorcortexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Connection(msg) => write!(f, "Connection error: {}", msg),
Self::Encode(msg) => write!(f, "Encode error: {}", msg),
Self::Decode(msg) => write!(f, "Decode error: {}", msg),
Self::ParameterNotFound(path) => write!(f, "Parameter not found: {}", path),
Self::Status(code) => write!(f, "Server status: {:?}", code),
Self::Io(msg) => write!(f, "I/O error: {}", msg),
Self::Subscription(msg) => write!(f, "Subscription error: {}", msg),
}
}
}
impl std::error::Error for MotorcortexError {}
impl From<prost::DecodeError> for MotorcortexError {
fn from(e: prost::DecodeError) -> Self {
Self::Decode(e.to_string())
}
}
pub type Result<T> = std::result::Result<T, MotorcortexError>;