agtrace_providers/
error.rs

1use std::fmt;
2
3/// Result type for agtrace-providers operations
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Error types that can occur in the providers layer
7#[derive(Debug)]
8pub enum Error {
9    /// IO operation failed
10    Io(std::io::Error),
11
12    /// JSON parsing failed
13    Json(serde_json::Error),
14
15    /// Provider not found or detection failed
16    Provider(String),
17
18    /// Session parsing failed (missing required fields, invalid format, etc.)
19    Parse(String),
20
21    /// Walkdir error
22    WalkDir(walkdir::Error),
23}
24
25impl fmt::Display for Error {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Error::Io(err) => write!(f, "IO error: {}", err),
29            Error::Json(err) => write!(f, "JSON error: {}", err),
30            Error::Provider(msg) => write!(f, "Provider error: {}", msg),
31            Error::Parse(msg) => write!(f, "Parse error: {}", msg),
32            Error::WalkDir(err) => write!(f, "Directory traversal error: {}", err),
33        }
34    }
35}
36
37impl std::error::Error for Error {
38    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39        match self {
40            Error::Io(err) => Some(err),
41            Error::Json(err) => Some(err),
42            Error::WalkDir(err) => Some(err),
43            Error::Provider(_) | Error::Parse(_) => None,
44        }
45    }
46}
47
48impl From<std::io::Error> for Error {
49    fn from(err: std::io::Error) -> Self {
50        Error::Io(err)
51    }
52}
53
54impl From<serde_json::Error> for Error {
55    fn from(err: serde_json::Error) -> Self {
56        Error::Json(err)
57    }
58}
59
60impl From<walkdir::Error> for Error {
61    fn from(err: walkdir::Error) -> Self {
62        Error::WalkDir(err)
63    }
64}