返回 CodeWhale
errors.rs
根目录 / crates / config / src / route / errors.rs
1 //! Route resolution errors (#3384).
2 //!
3 //! `thiserror` is not a dependency of this crate, so [`std::fmt::Display`] and
4 //! [`std::error::Error`] are hand-implemented. No new dependency is added.
5
6 use std::fmt;
7
8 use super::ids::ProviderId;
9
10 /// Why a [`super::resolver::RouteResolver`] could not produce a candidate.
11 #[derive(Debug, Clone)]
12 pub enum RouteError {
13 /// The requested model selector was empty.
14 EmptyModel,
15 /// The named provider could not be resolved.
16 InvalidProvider(String),
17 /// A model matched multiple providers; the caller must disambiguate.
18 AmbiguousModel(Vec<ProviderId>),
19 /// A clearly-foreign model was requested for a strict direct provider.
20 ForeignModelForDirectProvider {
21 /// The strict direct provider that rejected the model.
22 provider: ProviderId,
23 /// The foreign model selector that was rejected.
24 model: String,
25 },
26 /// A model-aware provider did not prove a supported request protocol for
27 /// the selected model/endpoint.
28 UnsupportedModelProtocol {
29 /// Provider whose catalog row was incomplete or unsupported.
30 provider: ProviderId,
31 /// Selected provider-owned model id.
32 model: String,
33 /// Catalog endpoint key, when one was present.
34 endpoint_key: String,
35 },
36 }
37
38 impl fmt::Display for RouteError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Self::EmptyModel => write!(f, "model selector was empty"),
42 Self::InvalidProvider(name) => write!(f, "invalid provider: {name}"),
43 Self::AmbiguousModel(providers) => {
44 let names: Vec<&str> = providers.iter().map(ProviderId::as_str).collect();
45 write!(
46 f,
47 "model matches multiple providers ({}); specify a provider",
48 names.join(", ")
49 )
50 }
51 Self::ForeignModelForDirectProvider { provider, model } => write!(
52 f,
53 "model {model:?} is not served by direct provider {}",
54 provider.as_str()
55 ),
56 Self::UnsupportedModelProtocol {
57 provider,
58 model,
59 endpoint_key,
60 } => write!(
61 f,
62 "model {model:?} on provider {} has unsupported or unproven endpoint {endpoint_key:?}",
63 provider.as_str()
64 ),
65 }
66 }
67 }
68
69 impl std::error::Error for RouteError {}
70
70 lines RUST