{"record":{"id":"8c67bc467c1f577d","repo":"Hmbown/CodeWhale","slug":"failed-to-update-setting-invalid-background-color","errorCode":null,"errorMessage":"Failed to update setting: invalid background_color '{value}'. Expected #RRGGBB, RRGGBB, or default.","messagePattern":"Failed to update setting: invalid background_color '(.+?)'\\. Expected #RRGGBB, RRGGBB, or default\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/settings.rs","lineNumber":2759,"sourceCode":"}\n\nfn normalize_optional_background_color(value: Option<&str>) -> Option<String> {\n    value.and_then(|raw| normalize_background_color_setting(raw).ok().flatten())\n}\n\nfn normalize_background_color_setting(value: &str) -> Result<Option<String>> {\n    let trimmed = value.trim();\n    if trimmed.is_empty()\n        || matches!(\n            trimmed.to_ascii_lowercase().as_str(),\n            \"default\" | \"none\" | \"reset\" | \"off\"\n        )\n    {\n        return Ok(None);\n    }\n\n    normalize_hex_rgb_color(trimmed).map(Some).ok_or_else(|| {\n        anyhow::anyhow!(\n            \"Failed to update setting: invalid background_color '{value}'. Expected #RRGGBB, RRGGBB, or default.\"\n        )\n    })\n}\n\nfn normalize_sidebar_focus(value: &str) -> &str {\n    match value.trim().to_ascii_lowercase().as_str() {\n        \"pinned\" | \"visible\" | \"show\" | \"on\" | \"work\" | \"plan\" | \"todos\" => \"pinned\",\n        \"tasks\" | \"activity\" | \"live\" | \"running\" => \"tasks\",\n        \"agents\" | \"subagents\" | \"sub-agents\" => \"agents\",\n        \"context\" => \"context\",\n        \"sessions\" | \"sessions_rail\" | \"session_history\" => \"sessions\",\n        \"hidden\" | \"hide\" | \"closed\" | \"off\" | \"none\" => \"hidden\",\n        _ => \"auto\",\n    }\n}\n\nfn is_false(value: &bool) -> bool {","sourceCodeStart":2741,"sourceCodeEnd":2777,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/settings.rs#L2741-L2777","documentation":"The TUI settings updater normalizes the 'background_color' setting via normalize_background_color_setting. An empty value or one of the aliases 'default'/'none'/'reset'/'off' (case-insensitive) is accepted and mapped to None (theme default). Any other value must parse as a 6-digit ASCII hex RGB color (optional leading '#') through normalize_hex_rgb_color; parse_hex_rgb_color rejects anything that is not exactly 6 hex digits. When parsing fails, this error is returned, echoing the offending value.","triggerScenarios":"Calling the settings-update API with background_color set to a named CSS color ('blue'), a 3-digit hex ('#fff'), rgb()/hsl() notation, a 7-digit hex, or any non-hex string. The value is trimmed and lowercased only for the alias check, so 'DEFAULT' works but 'transparent' does not.","commonSituations":"A model or config file copies colors from a CSS theme (named colors, #RGB shorthand), typos a 5- or 7-digit hex, or passes 'auto'/'transparent' expecting it to mean default.","solutions":["Use a 6-digit hex color with or without '#': '#1e1e2e' or '1e1e2e'.","To reset to the theme default, pass 'default' (or empty string, 'none', 'reset', 'off').","Check for stray characters: exactly 6 hex digits survive — '#fff', '#ffffff00', 'rgb(0,0,0)' are all rejected.","If a named color is wanted, convert it to hex first (e.g. 'blue' -> '#0000ff')."],"exampleFix":"// before\nset_setting(\"background_color\", \"blue\")\nset_setting(\"background_color\", \"#fff\")\n\n// after\nset_setting(\"background_color\", \"#0000ff\")\nset_setting(\"background_color\", \"default\")","handlingStrategy":"validation","validationCode":"fn is_valid_background_color(v: &str) -> bool {\n    let t = v.trim();\n    t.is_empty()\n        || matches!(t.to_ascii_lowercase().as_str(), \"default\" | \"none\" | \"reset\" | \"off\")\n        || {\n            let hex = t.strip_prefix('#').unwrap_or(t);\n            hex.len() == 6 && hex.chars().all(|c| c.is_ascii_hexdigit())\n        }\n}\n\nif !is_valid_background_color(value) {\n    return Err(format!(\"invalid background_color '{value}': use #RRGGBB, RRGGBB, or default\"));\n}\nset_setting(\"background_color\", value)?;","typeGuard":"function isHexRgbColor(value: string): boolean {\n  const t = value.trim();\n  const hex = t.startsWith('#') ? t.slice(1) : t;\n  return /^[0-9a-fA-F]{6}$/.test(hex);\n}","tryCatchPattern":null,"preventionTips":["Normalize every color to #RRGGBB before writing it to settings.","Treat named CSS colors as unsupported at this boundary and convert them to hex upstream.","Use 'default' (or empty string) to reset instead of inventing sentinel words like 'auto'."],"tags":["settings","color","validation","tui","hex-rgb"],"backgroundTag":"invalid-color-format","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}