agtrace_runtime/
error.rs

1use std::fmt;
2
3/// Result type for agtrace-runtime operations
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Error types that can occur in the runtime layer
7#[derive(Debug)]
8pub enum Error {
9    /// Database/index layer error
10    Index(agtrace_index::Error),
11
12    /// Provider layer error
13    Provider(agtrace_providers::Error),
14
15    /// IO operation failed
16    Io(std::io::Error),
17
18    /// Configuration error
19    Config(String),
20
21    /// Workspace not initialized
22    NotInitialized(String),
23
24    /// Invalid operation or state
25    InvalidOperation(String),
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Error::Index(err) => write!(f, "Index error: {}", err),
32            Error::Provider(err) => write!(f, "Provider error: {}", err),
33            Error::Io(err) => write!(f, "IO error: {}", err),
34            Error::Config(msg) => write!(f, "Configuration error: {}", msg),
35            Error::NotInitialized(msg) => write!(f, "Workspace not initialized: {}", msg),
36            Error::InvalidOperation(msg) => write!(f, "Invalid operation: {}", msg),
37        }
38    }
39}
40
41impl std::error::Error for Error {
42    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
43        match self {
44            Error::Index(err) => Some(err),
45            Error::Provider(err) => Some(err),
46            Error::Io(err) => Some(err),
47            Error::Config(_) | Error::NotInitialized(_) | Error::InvalidOperation(_) => None,
48        }
49    }
50}
51
52impl From<agtrace_index::Error> for Error {
53    fn from(err: agtrace_index::Error) -> Self {
54        Error::Index(err)
55    }
56}
57
58impl From<agtrace_providers::Error> for Error {
59    fn from(err: agtrace_providers::Error) -> Self {
60        Error::Provider(err)
61    }
62}
63
64impl From<std::io::Error> for Error {
65    fn from(err: std::io::Error) -> Self {
66        Error::Io(err)
67    }
68}
69
70impl From<toml::de::Error> for Error {
71    fn from(err: toml::de::Error) -> Self {
72        Error::Config(err.to_string())
73    }
74}
75
76impl From<toml::ser::Error> for Error {
77    fn from(err: toml::ser::Error) -> Self {
78        Error::Config(err.to_string())
79    }
80}