1use std::fmt;
2use std::io;
3
4#[derive(Debug)]
5pub enum WireError {
6 Io(io::Error),
7 Proto(prost::DecodeError),
8 FrameMagicMismatch,
9 FrameCrcMismatch,
10 FrameReadTimeout,
11 PayloadTooLarge(usize),
12 Timeout,
13 PermissionDenied(String),
14 Internal(String),
15}
16
17impl fmt::Display for WireError {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 match self {
20 WireError::Io(e) => write!(f, "io error: {}", e),
21 WireError::Proto(e) => write!(f, "proto decode error: {}", e),
22 WireError::FrameMagicMismatch => write!(f, "frame magic mismatch"),
23 WireError::FrameCrcMismatch => write!(f, "frame crc mismatch"),
24 WireError::FrameReadTimeout => write!(f, "timed out reading frame body"),
25 WireError::PayloadTooLarge(n) => write!(f, "payload too large: {} bytes", n),
26 WireError::Timeout => write!(f, "operation timed out"),
27 WireError::PermissionDenied(perm) => write!(f, "permission denied: {}", perm),
28 WireError::Internal(msg) => write!(f, "internal error: {}", msg),
29 }
30 }
31}
32
33impl std::error::Error for WireError {
34 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35 match self {
36 WireError::Io(e) => Some(e),
37 WireError::Proto(e) => Some(e),
38 _ => None,
39 }
40 }
41}
42
43impl From<io::Error> for WireError {
44 fn from(e: io::Error) -> Self {
45 WireError::Io(e)
46 }
47}
48
49impl From<prost::DecodeError> for WireError {
50 fn from(e: prost::DecodeError) -> Self {
51 WireError::Proto(e)
52 }
53}