Hmbown/CodeWhale · error · anyhow::Error

Failed to parse config file {}; file contents were omitted

Error message

Failed to parse config file {}; file contents were omitted

What it means

Startup config load failed to parse the TOML file (crates/tui/src/config.rs:4274): fs::read_to_string succeeded but toml::from_str did not. As with the /network loader, the file contents are omitted from the message because the config may hold secrets. The misplaced-key warning path only runs on successful parses, so syntax must be fixed first.

Source

Thrown at crates/tui/src/config.rs:4274

        Self::load_with_environment_policy(
            path,
            profile,
            ConfigEnvironmentPolicy::StructuralDiagnostic,
        )
    }

    fn load_with_environment_policy(
        path: Option<PathBuf>,
        profile: Option<&str>,
        environment_policy: ConfigEnvironmentPolicy,
    ) -> Result<Self> {
        let path = resolve_load_config_path(path)?;
        let mut config = if let Some(path) = path.as_ref() {
            if path.exists() {
                let contents = fs::read_to_string(path)
                    .with_context(|| format!("Failed to read config file: {}", path.display()))?;
                let parsed: ConfigFile = toml::from_str(&contents).map_err(|_| {
                    anyhow::anyhow!(
                        "Failed to parse config file {}; file contents were omitted",
                        codewhale_config::quote_os_path(path)
                    )
                })?;
                if let Some(msg) = warn_on_misplaced_top_level_keys(&contents) {
                    tracing::warn!("{msg}");
                }
                apply_profile(parsed, profile)?
            } else {
                Config::default()
            }
        } else {
            Config::default()
        };

        apply_env_overrides(&mut config, environment_policy);
        apply_managed_overrides(&mut config)?;
        apply_requirements(&mut config)?;

View on GitHub (pinned to 8880682c63)

Solutions

  1. Validate the file: python3 -c "import tomllib,sys; tomllib.load(open(sys.argv[1],'rb'))" <path> and fix the reported line
  2. Search for duplicate table/key definitions - TOML forbids redefining them
  3. Restore from backup or git history and reapply the change in one edit
  4. After it parses, act on any 'misplaced top-level keys' warning that then appears

Example fix

# config.toml - before
[providers.myhost]
api_base = "http://localhost:8000/v1"
[providers.myhost]          # duplicate table
context_window = 128000

# config.toml - after
[providers.myhost]
api_base = "http://localhost:8000/v1"
context_window = 128000
Defensive patterns

Strategy: validation

Validate before calling

// Dry-run parse in CI before shipping config
#[test]
fn config_parses() {
    let raw = std::fs::read_to_string("config.toml").unwrap();
    toml::from_str::<toml::Value>(&raw).expect("config.toml must parse");
}

Try / catch

// In loaders: never partially apply an unparseable config
let parsed = toml::from_str::<ConfigFile>(&raw).map_err(|e| anyhow!("aborting load: {e}"))?;

Prevention

When it happens

Trigger: Unclosed strings/brackets, duplicate keys, or invalid value syntax in the main config file; merge-conflict markers left in place; smart quotes or a BOM inserted by an editor.

Common situations: Hand edits right before launch; git merges touching config.toml; syncing configs across OSes with different editors.

Understand the failure class

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/afd94df6a23e1342. Report an issue: GitHub.