Skip to main content

systemprompt_models/services/providers/
error.rs

1//! Failure modes of
2//! [`ProviderRegistry::validate`](super::ProviderRegistry::validate): duplicate
3//! provider names, empty or SSRF-blocked endpoints, and duplicate or
4//! empty model ids/aliases. Connectivity is the registry's authority, so these
5//! are the only errors emitted while checking it.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10use thiserror::Error;
11
12#[derive(Debug, Error)]
13pub enum ProviderRegistryError {
14    #[error("provider registry declares provider name '{name}' more than once")]
15    DuplicateProvider { name: String },
16
17    #[error("provider registry entry '{name}' has an empty endpoint")]
18    EmptyEndpoint { name: String },
19
20    #[error(
21        "provider registry entry '{provider}' endpoint '{endpoint}' is not permitted: {reason}"
22    )]
23    BlockedEndpoint {
24        provider: String,
25        endpoint: String,
26        reason: String,
27    },
28
29    #[error(
30        "provider registry entry '{provider}' endpoint '{endpoint}' names a Google Cloud project literally; \
31         the project is derived from the service account in its secret — write `projects/{{project}}`"
32    )]
33    LiteralProjectInEndpoint { provider: String, endpoint: String },
34
35    #[error("provider registry model id or alias '{id}' is declared more than once")]
36    DuplicateModel { id: String },
37
38    #[error("provider registry model '{id}' has an empty id")]
39    EmptyModelId { id: String },
40
41    #[error("embedded default provider catalog failed to parse: {0}")]
42    InvalidDefaultCatalog(String),
43
44    #[error("embedded Vertex rate card failed to parse: {0}")]
45    InvalidVertexRateCard(String),
46}
47
48pub type ProviderRegistryResult<T> = Result<T, ProviderRegistryError>;