webterm_agent/models/
agent_error.rs

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use flatbuffers::InvalidFlatbuffer;
use std::fmt;
use tokio::sync::broadcast::error::RecvError;
use tokio::sync::mpsc::error::SendError;
use tokio_tungstenite::tungstenite;
use tokio_tungstenite::tungstenite::Bytes;
use webterm_core::models::reader_socket_error::ReaderSocketError;
use webterm_core::models::webterm_error::WebtermError;
use webterm_core::types::{ActivityId, FrontendId, SessionId};

#[derive(Debug)]
pub enum AgentError {
    RuntimeError(String),
    FlatbuffersError(InvalidFlatbuffer),
    FBParseError(String),
    SocketError(tungstenite::Error),
    SocketClosed,
    SocketSendError(SendError<Bytes>),
    SocketRecvError(RecvError),
    SocketReadError(ReaderSocketError),
    PtyProcessError(pty_process::Error),
    IOError(std::io::Error),
    URLParseError(url::ParseError),
    CoreError(WebtermError),
    FrontendNotFound(Option<FrontendId>),
    SessionNotFound(Option<SessionId>),
    ActivityNotFound(Option<ActivityId>),
    ReqwestError(reqwest::Error),
    RelayErrorAgentAlreadyExists,
}

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

impl fmt::Display for AgentError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            AgentError::RuntimeError(e) => write!(f, "Runtime error: {}", e),
            AgentError::FlatbuffersError(e) => write!(f, "Flatbuffers error: {}", e),
            AgentError::FBParseError(e) => write!(f, "Flatbuffers parse error: {}", e),
            AgentError::SocketError(e) => write!(f, "Socket error: {}", e),
            AgentError::SocketClosed => write!(f, "Socket closed"),
            AgentError::SocketSendError(e) => write!(f, "Socket send error: {}", e),
            AgentError::SocketRecvError(e) => write!(f, "Socket receive error: {}", e),
            AgentError::SocketReadError(e) => write!(f, "Socket read error: {}", e),
            AgentError::PtyProcessError(e) => write!(f, "Pty process error: {}", e),
            AgentError::IOError(e) => write!(f, "IO error: {}", e),
            AgentError::URLParseError(e) => write!(f, "URL parse error: {}", e),
            AgentError::CoreError(e) => write!(f, "CoreError: {}", e),
            AgentError::FrontendNotFound(e) => write!(f, "Frontend not found: {:?}", e),
            AgentError::SessionNotFound(e) => write!(f, "Session not found: {:?}", e),
            AgentError::ActivityNotFound(e) => write!(f, "Activity not found: {:?}", e),
            AgentError::ReqwestError(e) => write!(f, "Reqwest error: {}", e),
            AgentError::RelayErrorAgentAlreadyExists => write!(f, "Agent already exists"),
        }
    }
}

impl From<InvalidFlatbuffer> for AgentError {
    fn from(err: InvalidFlatbuffer) -> Self {
        AgentError::FlatbuffersError(err)
    }
}

impl From<SendError<Bytes>> for AgentError {
    fn from(err: SendError<Bytes>) -> Self {
        AgentError::SocketSendError(err)
    }
}

impl From<RecvError> for AgentError {
    fn from(err: RecvError) -> Self {
        AgentError::SocketRecvError(err)
    }
}

impl From<ReaderSocketError> for AgentError {
    fn from(err: ReaderSocketError) -> Self {
        AgentError::SocketReadError(err)
    }
}

impl From<tungstenite::Error> for AgentError {
    fn from(err: tungstenite::Error) -> Self {
        AgentError::SocketError(err)
    }
}

impl From<pty_process::Error> for AgentError {
    fn from(err: pty_process::Error) -> Self {
        AgentError::PtyProcessError(err)
    }
}

impl From<std::io::Error> for AgentError {
    fn from(err: std::io::Error) -> Self {
        AgentError::IOError(err)
    }
}

impl From<url::ParseError> for AgentError {
    fn from(err: url::ParseError) -> Self {
        AgentError::URLParseError(err)
    }
}

impl From<WebtermError> for AgentError {
    fn from(err: WebtermError) -> Self {
        AgentError::CoreError(err)
    }
}

impl From<reqwest::Error> for AgentError {
    fn from(err: reqwest::Error) -> Self {
        AgentError::ReqwestError(err)
    }
}