1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use super::proto::error::ProtoError;
use std::io;

#[derive(Debug)]
pub enum AgentError {
    User,
    Proto(ProtoError),
    IO(io::Error),
}

impl From<ProtoError> for AgentError {
    fn from(e: ProtoError) -> AgentError {
        AgentError::Proto(e)
    }
}

impl From<io::Error> for AgentError {
    fn from(e: io::Error) -> AgentError {
        AgentError::IO(e)
    }
}

impl std::fmt::Display for AgentError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            AgentError::User => write!(f, "Agent: User error"),
            AgentError::Proto(proto) => write!(f, "Agent: Protocol error: {}", proto),
            AgentError::IO(error) => write!(f, "Agent: I/O error: {}", error),
        }
    }
}

impl std::error::Error for AgentError {}