Skip to main content

systemprompt_models/errors/
provider.rs

1//! Typed errors returned across the 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//! keeping the provider's own error as the `#[source]` of the catch-all
7//! classes so the cause chain survives the seam.
8//!
9//! Copyright (c) systemprompt.io — Business Source License 1.1.
10//! See <https://systemprompt.io> for licensing details.
11
12use systemprompt_traits::BoxedSource;
13use thiserror::Error;
14
15#[derive(Debug, Error)]
16#[non_exhaustive]
17pub enum AiInferenceError {
18    #[error("provider {provider} rejected the request: {message}")]
19    Provider { provider: String, message: String },
20
21    #[error("no provider available for model {model}")]
22    NoProviderForModel { model: String },
23
24    #[error("provider {provider} rate limited the request: {details}")]
25    RateLimited { provider: String, details: String },
26
27    #[error("provider {provider} rejected the credentials")]
28    AuthenticationFailed { provider: String },
29
30    #[error("provider {provider} unavailable: {message}")]
31    Unavailable { provider: String, message: String },
32
33    #[error("inference request invalid: {0}")]
34    InvalidRequest(#[source] BoxedSource),
35
36    #[error("tool execution failed: {0}")]
37    Tool(#[source] BoxedSource),
38
39    #[error("configuration error: {0}")]
40    Configuration(#[source] BoxedSource),
41
42    #[error("persistence failed: {0}")]
43    Storage(#[source] BoxedSource),
44
45    #[error("{0}")]
46    Internal(#[source] BoxedSource),
47}
48
49pub type AiInferenceResult<T> = Result<T, AiInferenceError>;
50
51#[derive(Debug, Error)]
52#[non_exhaustive]
53pub enum McpRegistryError {
54    #[error("MCP server not found: {0}")]
55    NotFound(String),
56
57    #[error("MCP registry configuration error: {0}")]
58    Configuration(#[source] BoxedSource),
59
60    #[error("MCP transport failure for server {server}: {message}")]
61    Transport { server: String, message: String },
62
63    #[error("{0}")]
64    Internal(#[source] BoxedSource),
65}
66
67pub type McpRegistryResult<T> = Result<T, McpRegistryError>;