返回 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 /// The resolved route has no unambiguous Responses dialect profile.
27 ResponsesProfile {
28 /// Provider whose route was being resolved.
29 provider: ProviderId,
30 /// Profile selection failure.
31 detail: String,
32 },
33 /// A model-aware provider did not prove a supported request protocol for
34 /// the selected model/endpoint.
35 UnsupportedModelProtocol {
36 /// Provider whose catalog row was incomplete or unsupported.
37 provider: ProviderId,
38 /// Selected provider-owned model id.
39 model: String,
40 /// Catalog endpoint key, when one was present.
41 endpoint_key: String,
42 },
43 }
44
45 impl fmt::Display for RouteError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 Self::EmptyModel => write!(f, "model selector was empty"),
49 Self::InvalidProvider(name) => write!(f, "invalid provider: {name}"),
50 Self::AmbiguousModel(providers) => {
51 let names: Vec<&str> = providers.iter().map(ProviderId::as_str).collect();
52 write!(
53 f,
54 "model matches multiple providers ({}); specify a provider",
55 names.join(", ")
56 )
57 }
58 Self::ForeignModelForDirectProvider { provider, model } => write!(
59 f,
60 "model {model:?} is not served by direct provider {}",
61 provider.as_str()
62 ),
63 Self::ResponsesProfile { provider, detail } => write!(
64 f,
65 "provider {} responses profile: {detail}",
66 provider.as_str()
67 ),
68 Self::UnsupportedModelProtocol {
69 provider,
70 model,
71 endpoint_key,
72 } => {
73 write!(
74 f,
75 "model {model:?} on provider {} has unsupported or unproven endpoint {endpoint_key:?}",
76 provider.as_str()
77 )?;
78 // #6705: say which case this is, so a catalog Codewhale has not
79 // caught up with does not read as a broken install. The
80 // refresh remedy belongs to callers whose resolver actually
81 // reads the refreshed catalog, so it is not stated here.
82 match endpoint_key.as_str() {
83 "unproven" => write!(
84 f,
85 ": no catalog Codewhale has loaded proves this model's wire protocol. \
86 Reach it through a `kind = \"openai-compatible\"` provider with an \
87 explicit `wire`"
88 ),
89 super::OPENCODE_ZEN_DEPRECATED_ENDPOINT_KEY => write!(
90 f,
91 ": the provider's catalog marks this model deprecated; choose a current model"
92 ),
93 _ => write!(
94 f,
95 ": the provider serves this model over a protocol Codewhale does not speak"
96 ),
97 }
98 }
99 }
100 }
101 }
102
103 impl std::error::Error for RouteError {}
104
104 lines RUST