Skip to main content

gurty_cli/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum ServerError {
5    Io(std::io::Error),
6    InvalidPath(String),
7    InvalidConfiguration(String),
8    TlsConfiguration(String),
9    ServerStartup(String),
10}
11
12impl fmt::Display for ServerError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            ServerError::Io(err) => write!(f, "I/O error: {}", err),
16            ServerError::InvalidPath(path) => write!(f, "Invalid path: {}", path),
17            ServerError::InvalidConfiguration(msg) => write!(f, "Configuration error: {}", msg),
18            ServerError::TlsConfiguration(msg) => write!(f, "TLS configuration error: {}", msg),
19            ServerError::ServerStartup(msg) => write!(f, "Server startup error: {}", msg),
20        }
21    }
22}
23
24impl std::error::Error for ServerError {}
25
26impl From<std::io::Error> for ServerError {
27    fn from(err: std::io::Error) -> Self {
28        ServerError::Io(err)
29    }
30}
31
32impl From<gurtlib::GurtError> for ServerError {
33    fn from(err: gurtlib::GurtError) -> Self {
34        ServerError::ServerStartup(err.to_string())
35    }
36}
37
38pub type Result<T> = std::result::Result<T, ServerError>;