Hmbown/CodeWhale · error

Failed to parse configuration; file contents were omitted

Error message

Failed to parse configuration; file contents were omitted

What it means

Thrown by `Config::from_saved_document` when persisted configuration text cannot be parsed as TOML into `ConfigFile`. Like the other config parse errors in this codebase, the message intentionally omits the file contents because they may contain secrets; only the failure is reported. Profile precedence is applied only after a successful parse.

Solutions

  1. Validate the saved config text with a TOML parser and fix the syntax/schema error
  2. Regenerate the persisted configuration (delete it and let the app recreate defaults), then re-apply your profile
  3. If the file came from an older version, migrate its keys to the current ConfigFile schema
Defensive patterns

Strategy: try-catch

Validate before calling

contents.parse::<toml::Value>().map_err(|e| anyhow!("saved config TOML invalid: {e}"))?;

Try / catch

match Config::from_saved_document(&saved, profile) {
    Ok(cfg) => cfg,
    Err(e) if e.to_string().starts_with("Failed to parse configuration") => {
        eprintln!("Saved config is not valid TOML; regenerating defaults");
        Config::default()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `from_saved_document(contents, profile)` (e.g. tests or in-process reloads of saved config) with a `contents` string that `toml::from_str::<ConfigFile>` rejects.

Common situations: Loading a config snapshot saved by an older version whose schema has since changed; a corrupted persistence file; programmatically generated TOML with invalid syntax.

Understand the failure class

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/6a206fc0df5cf14d. Report an issue: GitHub.

Appendix: source

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

    /// Load configuration for a structural diagnostic without materializing
    /// secret-bearing environment values into the returned configuration.
    ///
    /// This still applies the ordinary safe routing, model, and policy
    /// overrides so doctor describes the runtime the user selected. Provider
    /// credentials are resolved only inside an explicit live-probe boundary.
    pub(crate) fn load_structural(path: Option<PathBuf>, profile: Option<&str>) -> Result<Self> {
        Self::load_with_environment_policy(
            path,
            profile,
            ConfigEnvironmentPolicy::StructuralDiagnostic,
        )
    }

    /// Parse persisted configuration through the same profile precedence used
    /// at startup, without environment, credentials, or filesystem writes.
    pub(crate) fn from_saved_document(contents: &str, profile: Option<&str>) -> Result<Self> {
        let parsed: ConfigFile = toml::from_str(contents).map_err(|_| {
            anyhow::anyhow!("Failed to parse configuration; file contents were omitted")
        })?;
        apply_profile(parsed, profile)
    }

    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 = Self::from_saved_document(&contents, profile).with_context(|| {
                    format!(
                        "Failed to load config file {}",
                        codewhale_config::quote_os_path(path)

View on GitHub (pinned to 73e0f67d83)