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("Not implemented: {0}")]
57 NotImplemented(String),
58
59 #[error("{0}")]
61 Other(String),
62}
63
64impl Error {
65 pub fn api(status: u16, message: impl Into<String>) -> Self {
67 Self::Api {
68 status,
69 message: message.into(),
70 }
71 }
72
73 pub fn missing_config(key: impl Into<String>) -> Self {
75 Self::MissingConfig(key.into())
76 }
77
78 pub fn unsupported_provider(provider: impl Into<String>) -> Self {
80 Self::UnsupportedProvider(provider.into())
81 }
82
83 pub fn unable_to_infer_provider(model: impl Into<String>) -> Self {
85 Self::UnableToInferProvider(model.into())
86 }
87
88 pub fn other(message: impl Into<String>) -> Self {
90 Self::Other(message.into())
91 }
92}