Skip to main content

vtcode_config/models/
errors.rs

1use std::fmt;
2
3use super::{ModelId, Provider};
4
5/// Error type for model parsing failures
6#[derive(Debug, Clone, PartialEq)]
7pub enum ModelParseError {
8    InvalidModel(String),
9    InvalidProvider(String),
10}
11
12impl fmt::Display for ModelParseError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            ModelParseError::InvalidModel(model) => {
16                write!(
17                    f,
18                    "Invalid model identifier: '{}'. Supported models: {}",
19                    model,
20                    ModelId::all_models()
21                        .iter()
22                        .map(|m| m.as_str())
23                        .collect::<Vec<_>>()
24                        .join(", ")
25                )
26            }
27            ModelParseError::InvalidProvider(provider) => {
28                write!(
29                    f,
30                    "Invalid provider: '{}'. Supported providers: {}",
31                    provider,
32                    Provider::all_providers()
33                        .iter()
34                        .map(|p| p.to_string())
35                        .collect::<Vec<_>>()
36                        .join(", ")
37                )
38            }
39        }
40    }
41}
42
43impl std::error::Error for ModelParseError {}