🐛 Fix config format detection — raw content check before deser
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -254,13 +254,22 @@ fn load_agent_config() -> gyandoot_core::config::AgentConfig {
|
|||||||
fn load_and_convert_config(path: &std::path::Path) -> Result<gyandoot_core::config::AgentConfig, Box<dyn std::error::Error>> {
|
fn load_and_convert_config(path: &std::path::Path) -> Result<gyandoot_core::config::AgentConfig, Box<dyn std::error::Error>> {
|
||||||
let content = std::fs::read_to_string(path)?;
|
let content = std::fs::read_to_string(path)?;
|
||||||
|
|
||||||
// Try parsing as canonical GyandootConfig first
|
// Detect format: flat `[provider]` (singular, from gyandoot setup) or
|
||||||
if let Ok(gyandoot_cfg) = toml::from_str::<gyandoot_core::config::GyandootConfig>(&content) {
|
// canonical `[providers]` (plural). We check the raw content because
|
||||||
|
// GyandootConfig has #[serde(default)] on everything — silent deser
|
||||||
|
// swallows unknown sections and returns defaults instead of erroring.
|
||||||
|
let is_flat_format = content.contains("[provider]\n")
|
||||||
|
|| content.contains("[provider]")
|
||||||
|
&& !content.contains("[providers]");
|
||||||
|
|
||||||
|
if !is_flat_format {
|
||||||
|
// Canonical format — parse directly
|
||||||
|
let gyandoot_cfg = toml::from_str::<gyandoot_core::config::GyandootConfig>(&content)?;
|
||||||
tracing::info!("Loaded config from {}", path.display());
|
tracing::info!("Loaded config from {}", path.display());
|
||||||
return Ok(gyandoot_core::config::AgentConfig::from(gyandoot_cfg));
|
return Ok(gyandoot_core::config::AgentConfig::from(gyandoot_cfg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: parse flat `[provider]` format and convert to canonical
|
// Flat `[provider]` format — parse and convert to canonical
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct FlatConfig {
|
struct FlatConfig {
|
||||||
provider: FlatProvider,
|
provider: FlatProvider,
|
||||||
|
|||||||
Reference in New Issue
Block a user