Hmbown/CodeWhale · error

Failed to update setting: invalid locale

Error message

Failed to update setting: invalid locale '{value}'. Expected: {}.

What it means

The settings setter rejected the value for `locale` (alias `language`) because normalize_configured_locale did not map it to a supported locale. The error interpolates the live list of valid locale values from codewhale_localization::configured_locale_values so the message always matches the current build.

Solutions

  1. Use one of the locale values listed in the error message itself.
  2. Check codewhale_localization::configured_locale_values for the authoritative list.
  3. Use the canonical short form shown there rather than display names or unlisted region variants.

Example fix

// before
settings.set("locale", "pt-BR")
// after
settings.set("locale", "pt")  // use a value from configured_locale_values
Defensive patterns

Strategy: validation

Validate before calling

// Validate against the live list before calling set
fn valid_locale(v: &str) -> bool {
    codewhale_localization::configured_locale_values(", ")
        .split(", ")
        .any(|l| l.eq_ignore_ascii_case(v.trim()))
}

Try / catch

if let Err(e) = settings.set("locale", value) {
    eprintln!("{e}"); // includes current valid locale list
}

Prevention

When it happens

Trigger: Settings update with key `locale` or `language` and a value not in the configured locale list, e.g. `set locale pt-BR` when only certain locales ship.

Common situations: Using a region variant that is not configured; mixing language codes and display names (e.g. `Deutsch` vs `de`); locale strings copied from BCP-47 contexts.

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/8be39346cba6f7cd. Report an issue: GitHub.

Appendix: source

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

            }
            "pin_last_prompt" | "pin_prompt" => {
                self.pin_last_prompt = parse_bool(value)?;
            }
            "show_tool_details" | "tool_details" => {
                self.show_tool_details = parse_bool(value)?;
            }
            "inline_diffs" | "inline_diff" | "diffs" => {
                let normalized = value.trim().to_ascii_lowercase();
                if !matches!(normalized.as_str(), "full" | "summary" | "off") {
                    anyhow::bail!(
                        "Failed to update setting: invalid inline diff mode '{value}'. Expected: full, summary, or off."
                    );
                }
                self.inline_diffs = normalized;
            }
            "locale" | "language" => {
                let Some(locale) = normalize_configured_locale(value) else {
                    anyhow::bail!(
                        "Failed to update setting: invalid locale '{value}'. Expected: {}.",
                        codewhale_localization::configured_locale_values(", ")
                    );
                };
                self.locale = locale.to_string();
            }
            "theme" | "ui_theme" => {
                self.theme = normalize_theme_setting(value).map_err(anyhow::Error::msg)?;
            }
            "background_color" | "background" | "bg" => {
                self.background_color = normalize_background_color_setting(value)?;
            }
            "composer_density" | "composer" => {
                let normalized = normalize_composer_density(value);
                if !["compact", "comfortable", "spacious"].contains(&normalized) {
                    anyhow::bail!(
                        "Failed to update setting: invalid composer density '{value}'. Expected: compact, comfortable, spacious."
                    );

View on GitHub (pinned to 73e0f67d83)