Hmbown/CodeWhale · error
Failed to update setting: invalid
Error message
Failed to update setting: invalid {key} '{value}'. Expected 0 or a positive integer. What it means
parse_usize_setting: a settings update expected a non-negative integer but the value did not parse as usize; the error names the setting key and offending value so the bad settings command is attributable.
Solutions
- Provide a plain non-negative integer (e.g. 0, 42)
- Remove signs, units, separators, and whitespace beyond trimming
- Use a value within usize range for your platform
Example fix
// before /context-budget 1,000 // after /context-budget 1000
Defensive patterns
Strategy: validation
Validate before calling
fn is_usize_setting(v: &str) -> bool { v.trim().parse::<usize>().is_ok() } Try / catch
match parse_usize_setting(key, value) {
Ok(n) => /* apply */,
Err(e) => eprintln!("{e:#}"),
} Prevention
- Strip units and thousands separators before passing numeric settings
- Reject negative numbers in UI input fields
- Cap inputs to realistic magnitudes to avoid usize overflow
When it happens
Trigger: Calling a numeric settings update (e.g. context budget, history size) with a non-integer, negative number, or a value above usize::MAX.
Common situations: Entering '-5' for a count; pasting a value with units like '1000ms'; locale-formatted numbers like '1,000'; very large numbers.
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
- context_window must be greater than 0
- Failed to update setting
- agent profile provider cannot be empty
- agent profile provider must be a simple provider id
- api_key cannot be empty string
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/a19fadd2e91900b8.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/settings.rs:2815
"on" | "true" | "yes" | "1" | "enabled" => Ok(true),
"off" | "false" | "no" | "0" | "disabled" => Ok(false),
_ => {
anyhow::bail!("Failed to parse boolean '{value}': expected on/off, true/false, yes/no.")
}
}
}
fn default_thinking_preview_lines() -> usize {
2
}
fn default_true() -> bool {
true
}
fn parse_usize_setting(key: &str, value: &str) -> Result<usize> {
value.trim().parse::<usize>().map_err(|_| {
anyhow::anyhow!(
"Failed to update setting: invalid {key} '{value}'. Expected 0 or a positive integer."
)
})
}
fn parse_u16_range(key: &str, value: &str, min: u16, max: u16) -> Result<u16> {
let parsed = value
.trim()
.parse::<u16>()
.map_err(|_| anyhow::anyhow!("Invalid {key} '{value}': expected {min}-{max}"))?;
if !(min..=max).contains(&parsed) {
anyhow::bail!("Invalid {key} '{value}': expected {min}-{max}");
}
Ok(parsed)
}
fn parse_percent_setting(key: &str, value: &str) -> Result<f64> {
let trimmed = value.trim().trim_end_matches('%').trim();View on GitHub (pinned to 73e0f67d83)