Repository: TabbyML/tabby
File: crates/tabby-common/src/config.rs (Rust)

Code before:
                ],
            )
            .print();
        }

        Ok(cfg)
    }

    #[cfg(feature = "testutils")]
    pub fn save(&self) {
        serdeconv::to_toml_file(self, crate::path::config_file().as_path())
            .expect("Failed to write config file");
    }

    fn validate_dirs(&self) -> Result<()> {
        let mut dirs = HashSet::new();
        for repo in self.repositories.iter() {
            let dir = repo.dir().display().to_string();
            if !dirs.insert(dir.clone()) {
                return Err(anyhow!("Duplicate directory in `repositories`: {}", dir));
            }
        }
        Ok(())
    }

    fn validate_models(&self) -> Result<()> {
        Self::validate_model_config(&self.model.completion)?;
        Self::validate_model_config(&self.model.chat)?;

        Ok(())
    }

    fn validate_model_config(model_config: &Option<ModelConfig>) -> Result<()> {
        if let Some(config::ModelConfig::Http(completion_http_config)) = &model_config
        {
            if let Some(models) = &completion_http_config.supported_models {
                if let Some(model_name) = &completion_http_config.model_name {
                    if !models.contains(model_name) {
                        return Err(anyhow!("Suppported model list does not contain model: {}", model_name));
                    }
                }                 
            }
        }

        Ok(())
    }
}

lazy_static! {
    static ref HASHER: HashIds = HashIds::builder()
        .with_salt("tabby-config-id-serializer")

Review comment (suggestion):
```suggestion
    fn validate_config(&self) -> Result<()> {
```

Code after:
                    "Falling back to default config, please resolve the errors and restart Tabby",
                ],
            )
            .print();
            process::exit(1);
        }

        Ok(cfg)
    }

    #[cfg(feature = "testutils")]
    pub fn save(&self) {
        serdeconv::to_toml_file(self, crate::path::config_file().as_path())
            .expect("Failed to write config file");
    }

    fn validate_dirs(&self) -> Result<()> {
        let mut dirs = HashSet::new();
        for repo in self.repositories.iter() {
            let dir = repo.dir().display().to_string();
            if !dirs.insert(dir.clone()) {
                return Err(anyhow!("Duplicate directory in `repositories`: {}", dir));
            }
        }
        Ok(())
    }

    fn validate_config(&self) -> Result<()> {
        Self::validate_model_config(&self.model.completion)?;
        Self::validate_model_config(&self.model.chat)?;

        Ok(())
    }

    fn validate_model_config(model_config: &Option<ModelConfig>) -> Result<()> {
        if let Some(config::ModelConfig::Http(completion_http_config)) = &model_config {
            if let Some(models) = &completion_http_config.supported_models {
                if let Some(model_name) = &completion_http_config.model_name {
                    if !models.contains(model_name) {
                        return Err(anyhow!(
                            "Suppported model list does not contain model: {}",
                            model_name
                        ));
                    }
                }
            }
        }

        Ok(())
    }
}