agtrace_sdk/
error.rs

1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7    NotFound(String),
8    InvalidInput(String),
9    Runtime(agtrace_runtime::Error),
10}
11
12impl fmt::Display for Error {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Error::NotFound(msg) => write!(f, "Not found: {}", msg),
16            Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
17            Error::Runtime(err) => write!(f, "{}", err),
18        }
19    }
20}
21
22impl std::error::Error for Error {
23    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
24        match self {
25            Error::Runtime(err) => Some(err),
26            _ => None,
27        }
28    }
29}
30
31impl From<agtrace_runtime::Error> for Error {
32    fn from(err: agtrace_runtime::Error) -> Self {
33        Error::Runtime(err)
34    }
35}