agent_chain_core/
error.rs1use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Debug, Error)]
13pub enum Error {
14 #[error("HTTP error: {0}")]
16 Http(#[from] reqwest::Error),
17
18 #[error("JSON error: {0}")]
20 Json(#[from] serde_json::Error),
21
22 #[error("IO error: {0}")]
24 Io(#[from] std::io::Error),
25
26 #[error("API error ({status}): {message}")]
28 Api {
29 status: u16,
31 message: String,
33 },
34
35 #[error("Missing configuration: {0}")]
37 MissingConfig(String),
38
39 #[error("Unsupported provider: {0}")]
41 UnsupportedProvider(String),
42
43 #[error("Unable to infer provider for model '{0}'. Please specify model_provider explicitly.")]
45 UnableToInferProvider(String),
46
47 #[error("Invalid configuration: {0}")]
49 InvalidConfig(String),
50
51 #[error("Tool invocation error: {0}")]
53 ToolInvocation(String),
54
55 #[error("{0}")]
57 Other(String),
58}
59
60impl Error {
61 pub fn api(status: u16, message: impl Into<String>) -> Self {
63 Self::Api {
64 status,
65 message: message.into(),
66 }
67 }
68
69 pub fn missing_config(key: impl Into<String>) -> Self {
71 Self::MissingConfig(key.into())
72 }
73
74 pub fn unsupported_provider(provider: impl Into<String>) -> Self {
76 Self::UnsupportedProvider(provider.into())
77 }
78
79 pub fn unable_to_infer_provider(model: impl Into<String>) -> Self {
81 Self::UnableToInferProvider(model.into())
82 }
83
84 pub fn other(message: impl Into<String>) -> Self {
86 Self::Other(message.into())
87 }
88}