{"record":{"id":"4d841430392fdefe","repo":"Hmbown/CodeWhale","slug":"failed-to-update-setting-invalid-max-history-va","errorCode":null,"errorMessage":"Failed to update setting: invalid max history '{value}'. Expected a positive number.","messagePattern":"Failed to update setting: invalid max history '(.+?)'\\. Expected a positive number\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/settings.rs","lineNumber":1738,"sourceCode":"                        \"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\" => {\n                anyhow::bail!(\n                    \"Model defaults belong to config.toml. Use /model and choose Remember as my default, or /config model <id> --save.\"\n                );\n            }\n            \"reasoning_effort\" | \"effort\" => {\n                self.reasoning_effort = normalize_reasoning_effort_setting(value)?;\n            }\n            \"permission_posture\" | \"permissions\" => {\n                self.permission_posture = normalize_permission_posture(value);\n                if self.permission_posture.is_none() {\n                    anyhow::bail!(\n                        \"Failed to update setting: invalid permission posture '{value}'. Expected: ask, auto-review, or full-access.\"\n                    );\n                }\n            }\n            \"sandbox_mode\" | \"sandbox\" | \"filesystem_sandbox\" => {\n                self.sandbox_mode = normalize_sandbox_mode(value);\n                if self.sandbox_mode.is_none() {\n                    anyhow::bail!(","sourceCodeStart":1720,"sourceCodeEnd":1756,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/settings.rs#L1720-L1756","documentation":"Settings::set parses the `max_history`/`history` value as usize via str::parse; a parse failure produces this error. The message says 'positive number' though the type also accepts 0 — only non-numeric (or, on some platforms, overflowingly large) strings fail.","triggerScenarios":"Settings::set(\"max_history\", v) where v is not a valid usize literal — e.g. `history fifty`, `history 1000 entries`, `history -5`, or a value exceeding usize::MAX on 32-bit targets.","commonSituations":"Scripted /config commands passing prose or units ('5000 lines'), locales formatting numbers with separators ('10,000'), or negative numbers.","solutions":["Pass a plain non-negative integer with no units or separators, e.g. `100`.","Strip whitespace; str::parse does not trim trailing text.","On 32-bit builds, keep the value within u32 range to avoid overflow rejections."],"exampleFix":"// before\nsettings.set(\"max_history\", \"10,000\")?;\n// after\nsettings.set(\"max_history\", \"10000\")?;","handlingStrategy":"validation","validationCode":"fn valid_max_history(v: &str) -> bool {\n    v.trim().parse::<usize>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"match value.trim().parse::<usize>() {\n    Ok(n) => settings.set(\"max_history\", &n.to_string())?,\n    Err(_) => eprintln!(\"max_history must be a plain positive integer\"),\n}","preventionTips":["Parse numeric user input in the wrapper first; reject units and separators.","Serialize numbers with .to_string(), never locale formatting.","Clamp values in your UI before writing."],"tags":["rust","configuration","parsing"],"backgroundTag":"invalid-argument-format","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"}