Skip to main content

systemprompt_provider_contracts/
error.rs

1//! Public error type for provider trait contracts.
2//!
3//! [`ProviderError`] is the concrete error returned by every provider trait
4//! that does not have a domain-specific error of its own (LLM and tool
5//! providers carry their own typed errors — see [`crate::llm`] and
6//! [`crate::tool`]).
7//!
8//! Downstream provider crates that implement these traits typically use
9//! `anyhow::Error` internally; the `#[from]` impl lets them propagate with
10//! `?` while still presenting a typed error at the public boundary.
11
12use thiserror::Error;
13
14#[derive(Debug, Error)]
15pub enum ProviderError {
16    #[error("Provider configuration error: {0}")]
17    Configuration(String),
18
19    #[error("Resource not found: {0}")]
20    NotFound(String),
21
22    #[error("Invalid input: {0}")]
23    InvalidInput(String),
24
25    #[error("Render failed: {0}")]
26    RenderFailed(String),
27
28    #[error("I/O error: {0}")]
29    Io(#[from] std::io::Error),
30
31    #[error("YAML error: {0}")]
32    Yaml(#[from] serde_yaml::Error),
33
34    #[error("JSON error: {0}")]
35    Json(#[from] serde_json::Error),
36
37    #[error("Internal provider error: {0}")]
38    Internal(#[source] anyhow::Error),
39}
40
41impl From<anyhow::Error> for ProviderError {
42    fn from(err: anyhow::Error) -> Self {
43        Self::Internal(err)
44    }
45}
46
47pub type ProviderResult<T> = Result<T, ProviderError>;