Skip to main content

systemprompt_models/errors/
provider.rs

1//! Typed errors returned across the dyn-dispatched provider seams
2//! ([`crate::ai::AiProvider`], [`crate::mcp::McpRegistry`] and friends).
3//!
4//! Each variant names the failure class a caller can act on; the concrete
5//! provider maps its own error hierarchy onto these before crossing the seam,
6//! so consumers never see a boxed, opaque error.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11use thiserror::Error;
12
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum AiInferenceError {
16    #[error("provider {provider} rejected the request: {message}")]
17    Provider { provider: String, message: String },
18
19    #[error("no provider available for model {model}")]
20    NoProviderForModel { model: String },
21
22    #[error("provider {provider} rate limited the request: {details}")]
23    RateLimited { provider: String, details: String },
24
25    #[error("provider {provider} rejected the credentials")]
26    AuthenticationFailed { provider: String },
27
28    #[error("provider {provider} unavailable: {message}")]
29    Unavailable { provider: String, message: String },
30
31    #[error("inference request invalid: {0}")]
32    InvalidRequest(String),
33
34    #[error("tool execution failed: {0}")]
35    Tool(String),
36
37    #[error("configuration error: {0}")]
38    Configuration(String),
39
40    #[error("persistence failed: {0}")]
41    Storage(String),
42
43    #[error("{0}")]
44    Internal(String),
45}
46
47pub type AiInferenceResult<T> = Result<T, AiInferenceError>;
48
49#[derive(Debug, Error)]
50#[non_exhaustive]
51pub enum McpRegistryError {
52    #[error("MCP server not found: {0}")]
53    NotFound(String),
54
55    #[error("MCP registry configuration error: {0}")]
56    Configuration(String),
57
58    #[error("MCP transport failure for server {server}: {message}")]
59    Transport { server: String, message: String },
60
61    #[error("{0}")]
62    Internal(String),
63}
64
65pub type McpRegistryResult<T> = Result<T, McpRegistryError>;