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 convert any
9//! third-party error at the boundary with
10//! `.map_err(|e| ProviderError::Internal(e.to_string()))`.
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(String),
39}
40
41pub type ProviderResult<T> = Result<T, ProviderError>;