Hmbown/CodeWhale · warning

Failed to update setting: invalid tool collapse mode

Error message

Failed to update setting: invalid tool collapse mode '{value}'. Expected: compact, expanded, or calm.

What it means

The set()/update-setting handler validates user-provided values before mutating fields. For the tool_collapse setting, the raw string is normalized and must resolve to one of the accepted modes (compact, expanded, calm); anything else is rejected with this error instead of silently storing an unknown mode.

Solutions

  1. Pass one of the exact accepted values: compact, expanded, or calm
  2. Use the /config UI picker for tool_collapse instead of free-text entry to avoid typos
  3. Check normalize_tool_collapse_mode for accepted aliases and update any script that passes legacy names

Example fix

// before
settings.set("tool_collapse", "minimal")?; // Err: invalid tool collapse mode
// after
settings.set("tool_collapse", "calm")?; // Ok
Defensive patterns

Strategy: validation

Validate before calling

const MODES: [&str; 3] = ["compact", "expanded", "calm"];
fn valid_mode(v: &str) -> bool { MODES.contains(&v.trim().to_lowercase().as_str()) }

Type guard

fn as_collapse_mode(v: &str) -> Option<&'static str> {
    match v.trim().to_lowercase().as_str() {
        "compact" => Some("compact"),
        "expanded" => Some("expanded"),
        "calm" => Some("calm"),
        _ => None,
    }
}

Try / catch

match settings.set("tool_collapse", value) {
    Ok(_) => {},
    Err(e) => eprintln!("{e}; expected compact, expanded, or calm"),
}

Prevention

When it happens

Trigger: Calling the update-setting entry point with key `tool_collapse`, `tool_collapse_mode`, or `collapse` and a value string that normalizes outside {compact, expanded, calm} — e.g. "minimal", "true", "", "Collapsed", or a misspelling like "colmapsed".

Common situations: User typed an invalid mode in /config; a script or alias passes an old mode name that predates the current set of allowed values; case/spacing mistakes like " Calm ".

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/settings.rs:1509

        let canonical = Self::canonical_key(key);
        match key {
            "auto_compact" | "compact" => {
                self.auto_compact = parse_bool(value)?;
                self.auto_compact_explicit = true;
            }
            "auto_compact_threshold" | "auto_compact_threshold_percent" => {
                self.auto_compact_threshold_percent =
                    parse_percent_setting("auto_compact_threshold_percent", value)?;
                self.auto_compact = true;
                self.auto_compact_explicit = true;
            }
            "calm_mode" | "calm" => {
                self.calm_mode = parse_bool(value)?;
            }
            "tool_collapse" | "tool_collapse_mode" | "collapse" => {
                let normalized = normalize_tool_collapse_mode(value);
                if !matches!(normalized, "compact" | "expanded" | "calm") {
                    return Err(anyhow::anyhow!(
                        "Failed to update setting: invalid tool collapse mode '{value}'. Expected: compact, expanded, or calm."
                    ));
                }
                self.tool_collapse_mode = normalized.to_string();
            }
            "low_motion" | "motion" => {
                self.low_motion = parse_bool(value)?;
            }
            "fancy_animations" | "fancy" | "animations" => {
                self.fancy_animations = parse_bool(value)?;
            }
            "focus_texture" | "texture" => {
                let normalized = value.trim().to_ascii_lowercase();
                if !matches!(normalized.as_str(), "off" | "scrim" | "grain") {
                    anyhow::bail!(
                        "Failed to update setting: invalid focus texture '{value}'. Expected: off, scrim, or grain."
                    );
                }

View on GitHub (pinned to 73e0f67d83)