motorcortex_rust/
error.rs1use crate::msg::StatusCode;
2use std::fmt;
3
4#[derive(Debug)]
6pub enum MotorcortexError {
7 Connection(String),
9
10 Encode(String),
12
13 Decode(String),
15
16 ParameterNotFound(String),
18
19 Status(StatusCode),
21
22 Io(String),
24
25 Subscription(String),
27}
28
29impl fmt::Display for MotorcortexError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::Connection(msg) => write!(f, "Connection error: {}", msg),
33 Self::Encode(msg) => write!(f, "Encode error: {}", msg),
34 Self::Decode(msg) => write!(f, "Decode error: {}", msg),
35 Self::ParameterNotFound(path) => write!(f, "Parameter not found: {}", path),
36 Self::Status(code) => write!(f, "Server status: {:?}", code),
37 Self::Io(msg) => write!(f, "I/O error: {}", msg),
38 Self::Subscription(msg) => write!(f, "Subscription error: {}", msg),
39 }
40 }
41}
42
43impl std::error::Error for MotorcortexError {}
44
45impl From<prost::DecodeError> for MotorcortexError {
46 fn from(e: prost::DecodeError) -> Self {
47 Self::Decode(e.to_string())
48 }
49}
50
51pub type Result<T> = std::result::Result<T, MotorcortexError>;