{"record":{"id":"cc1bc93b03ebb3ed","repo":"Hmbown/CodeWhale","slug":"failed-to-update-setting-invalid-cost-currency","errorCode":null,"errorMessage":"Failed to update setting: invalid cost currency '{value}'. Expected: usd, cny, rmb, yuan.","messagePattern":"Failed to update setting: invalid cost currency '(.+?)'\\. Expected: usd, cny, rmb, yuan\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/settings.rs","lineNumber":1719,"sourceCode":"                    \"plan\" => \"plan\".to_string(),\n                    \"operate\" | \"operation\" | \"ops\" => \"operate\".to_string(),\n                    _ => anyhow::bail!(\n                        \"Failed to update setting: invalid mode '{value}'. Expected: act (agent), plan, or operate.\"\n                    ),\n                };\n            }\n            \"context_panel\" | \"context\" | \"session_panel\" => {\n                self.context_panel = parse_bool(value)?;\n            }\n            \"sessions_rail\" | \"sessions_panel\" | \"session_rail\" => {\n                self.sessions_rail = parse_bool(value)?;\n            }\n            \"session_auto_resume\" | \"auto_resume\" => {\n                self.session_auto_resume = parse_bool(value)?;\n            }\n            \"cost_currency\" | \"currency\" => {\n                let Some(currency) = crate::pricing::CostCurrency::from_setting(value) else {\n                    anyhow::bail!(\n                        \"Failed to update setting: invalid cost currency '{value}'. Expected: usd, cny, rmb, yuan.\"\n                    );\n                };\n                self.cost_currency = match currency {\n                    crate::pricing::CostCurrency::Usd => \"usd\",\n                    crate::pricing::CostCurrency::Cny => \"cny\",\n                }\n                .to_string();\n            }\n            \"max_history\" | \"history\" => {\n                let max: usize = value.parse().map_err(|_| {\n                    anyhow::anyhow!(\n                        \"Failed to update setting: invalid max history '{value}'. Expected a positive number.\"\n                    )\n                })?;\n                self.max_input_history = max;\n            }\n            \"default_model\" | \"model\" => {","sourceCodeStart":1701,"sourceCodeEnd":1737,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/settings.rs#L1701-L1737","documentation":"Settings::set resolves the `cost_currency`/`currency` value through crate::pricing::CostCurrency::from_setting. When that returns None the setter bails. The canonical storage values are \"usd\" and \"cny\"; the error additionally advertises rmb and yuan as accepted spellings of CNY.","triggerScenarios":"Settings::set(\"cost_currency\", v) where from_setting(v) returns None — e.g. `currency EUR`, `currency dollars`, or a trailing-space/emoji variant the parser does not strip.","commonSituations":"Users wanting costs displayed in a currency that is not supported (only USD and CNY exist), or typing informal currency names (bucks, ¥).","solutions":["Use usd, cny, rmb, or yuan.","If you need another currency, it is not implemented — file/inspect a feature request in the pricing module.","Verify the exact string in CostCurrency::from_setting in crates/tui/src/pricing.rs."],"exampleFix":"// before\nsettings.set(\"cost_currency\", \"eur\")?;\n// after\nsettings.set(\"cost_currency\", \"usd\")?;","handlingStrategy":"validation","validationCode":"fn valid_currency(v: &str) -> bool {\n    matches!(v.trim().to_ascii_lowercase().as_str(), \"usd\" | \"cny\" | \"rmb\" | \"yuan\")\n}","typeGuard":null,"tryCatchPattern":"match settings.set(\"cost_currency\", value) {\n    Err(e) if e.to_string().contains(\"invalid cost currency\") => eprintln!(\"only USD and CNY are supported\"),\n    r => r?,\n}","preventionTips":["Check the supported currency list before exposing a currency picker in wrappers.","Do not invent currency codes; only USD/CNY exist.","Normalize CNY aliases (rmb, yuan) to cny in your own input handling."],"tags":["rust","configuration","validation","currency"],"backgroundTag":"invalid-config-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}