1use std::error::Error as StdError;
4use std::fmt;
5
6pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug)]
11pub enum Error {
12 Library(String),
14
15 Agent(String),
17
18 ApiKey(String),
20
21 Connection(String),
23
24 Timeout(String),
26
27 Config(String),
29
30 Disposed,
32
33 #[cfg(feature = "auth")]
35 Auth(String),
36}
37
38impl fmt::Display for Error {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Error::Library(msg) => write!(f, "Library error: {}", msg),
42 Error::Agent(msg) => write!(f, "Agent error: {}", msg),
43 Error::ApiKey(msg) => write!(f, "API key error: {}", msg),
44 Error::Connection(msg) => write!(f, "Connection error: {}", msg),
45 Error::Timeout(msg) => write!(f, "Timeout error: {}", msg),
46 Error::Config(msg) => write!(f, "Configuration error: {}", msg),
47 Error::Disposed => write!(f, "Agent has been disposed"),
48 #[cfg(feature = "auth")]
49 Error::Auth(msg) => write!(f, "Auth error: {}", msg),
50 }
51 }
52}
53
54impl StdError for Error {}
55
56impl Error {
57 pub fn agent<S: Into<String>>(msg: S) -> Self {
59 Error::Agent(msg.into())
60 }
61
62 pub fn library<S: Into<String>>(msg: S) -> Self {
64 Error::Library(msg.into())
65 }
66
67 pub fn connection<S: Into<String>>(msg: S) -> Self {
69 Error::Connection(msg.into())
70 }
71
72 pub fn timeout<S: Into<String>>(msg: S) -> Self {
74 Error::Timeout(msg.into())
75 }
76
77 pub fn config<S: Into<String>>(msg: S) -> Self {
79 Error::Config(msg.into())
80 }
81
82 #[cfg(feature = "auth")]
84 pub fn auth<S: Into<String>>(msg: S) -> Self {
85 Error::Auth(msg.into())
86 }
87}