Skip to main content

keep_running/
error.rs

1use std::fmt;
2use std::io;
3
4#[allow(dead_code)]
5#[derive(Debug)]
6pub enum KeepError {
7    SessionNotFound(String),
8    SessionExists(String),
9    NoSessions,
10    ConnectionFailed(String),
11    Protocol(String),
12    Io(io::Error),
13    ChildExited(i32),
14    ChildSignaled,
15    Other(String),
16}
17
18impl fmt::Display for KeepError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            KeepError::SessionNotFound(s) => write!(f, "Session not found: {}", s),
22            KeepError::SessionExists(s) => write!(f, "Session already exists: {}", s),
23            KeepError::NoSessions => write!(f, "No sessions running"),
24            KeepError::ConnectionFailed(s) => write!(f, "Failed to connect to session: {}", s),
25            KeepError::Protocol(s) => write!(f, "Protocol error: {}", s),
26            KeepError::Io(e) => write!(f, "IO error: {}", e),
27            KeepError::ChildExited(code) => write!(f, "Child process exited with code: {}", code),
28            KeepError::ChildSignaled => write!(f, "Child process killed by signal"),
29            KeepError::Other(s) => write!(f, "{}", s),
30        }
31    }
32}
33
34impl std::error::Error for KeepError {}
35
36impl From<io::Error> for KeepError {
37    fn from(err: io::Error) -> Self {
38        KeepError::Io(err)
39    }
40}
41
42#[allow(dead_code)]
43pub type Result<T> = std::result::Result<T, KeepError>;