Skip to main content

windbgr_mcp/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("io error: {0}")]
8    Io(#[from] std::io::Error),
9
10    #[error("invalid configuration: {0}")]
11    Config(String),
12
13    #[error("cdb executable not found: {0}")]
14    CdbNotFound(String),
15
16    #[error("cdb session not found: {0}")]
17    SessionNotFound(String),
18
19    #[error("cdb session limit reached (max = {0})")]
20    SessionLimit(usize),
21
22    #[error("invalid session state: {current} — {action} not allowed")]
23    InvalidState { current: String, action: String },
24
25    #[error("cdb session exited unexpectedly: {0}")]
26    CdbExited(String),
27
28    #[error("operation timed out after {0} ms")]
29    Timeout(u64),
30
31    #[error("windows api error: {0}")]
32    WindowsApi(String),
33
34    #[error("{0}")]
35    Other(String),
36}
37
38impl Error {
39    pub fn other(msg: impl Into<String>) -> Self {
40        Error::Other(msg.into())
41    }
42}
43
44impl From<anyhow::Error> for Error {
45    fn from(value: anyhow::Error) -> Self {
46        Error::Other(value.to_string())
47    }
48}
49
50impl From<toml::de::Error> for Error {
51    fn from(value: toml::de::Error) -> Self {
52        Error::Config(value.to_string())
53    }
54}