Hmbown/CodeWhale · error · anyhow::Error

active profile is missing or malformed

Error message

active profile is missing or malformed

What it means

While building the TOML edit path for a scoped config value, the active profile (`app.config_profile`) is either absent from the document's `profiles` table or is not a TOML table (malformed). The command errors instead of writing settings into a nonexistent profile section.

Solutions

  1. Check `profiles.<active-profile>` exists as a table in the config TOML
  2. Correct the profile name typo or create the profile section
  3. Ensure the profile value is a table, not a scalar
  4. Recreate the profile via the config command so it materializes on disk

Example fix

// before
[profiles]
work = "oops"
// after
[profiles.work.tui]
# profile must be a table with its settings
Defensive patterns

Strategy: validation

Validate before calling

// precheck: profile must exist as a table before scoped writes
let has_profile = doc.get("profiles")
    .and_then(|p| p.get(profile))
    .and_then(toml_edit::Item::as_table_like)
    .is_some();

Try / catch

match set_config_value(app, key, value) {
    Err(e) if e.to_string().contains("active profile is missing") => {
        eprintln!("Create [profiles.{}] in config first", app.config_profile.unwrap_or_default());
    }
    other => other?,
}

Prevention

When it happens

Trigger: set_config_value (crates/tui/src/commands/groups/config/config.rs:2488) reads the config TOML, looks up doc["profiles"][profile], and it is missing or not a table_like while `app.config_profile` is Some — e.g. profile set in app state but never materialized in the file.

Common situations: Hand-edited config.toml that deleted or renamed the profile section, a profile name typo, a profile defined as a non-table value (e.g. string), or switching profiles in the UI before the profile was persisted.

Understand the failure class

Related errors


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

Appendix: source

Thrown at crates/tui/src/commands/groups/config/config.rs:2488

                        ),
                );
            };
            let value = preset.as_setting();
            let scope = if persist {
                let saved = crate::config_persistence::config_toml_path(app.config_path.as_deref())
                    .and_then(|path| {
                        crate::config_persistence::mutate_config_document(&path, |doc| {
                            // Profiles replace the whole TUI table on load. Edit its
                            // existing owner without creating an empty override that
                            // would reset the other inherited display settings.
                            let mut segments = Vec::new();
                            if let Some(profile) = app.config_profile.as_deref() {
                                let table = doc
                                    .get("profiles")
                                    .and_then(|v| v.get(profile))
                                    .and_then(toml_edit::Item::as_table_like)
                                    .ok_or_else(|| {
                                        anyhow::anyhow!("active profile is missing or malformed")
                                    })?;
                                if table.contains_key("tui") {
                                    segments.extend(["profiles", profile]);
                                }
                            }
                            segments.extend(["tui", row_key]);
                            crate::config_persistence::set_document_value(doc, &segments, value)
                        })?;
                        Ok(path)
                    });
                match saved {
                    Ok(path) => format!(
                        "{} {}",
                        tr(app.ui_locale, MessageId::ConfigScopeSaved),
                        path.display()
                    ),
                    Err(error) => {
                        return CommandResult::error(

View on GitHub (pinned to 73e0f67d83)