Hmbown/CodeWhale · error
Failed to update setting: invalid
Error message
Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100. What it means
parse_percent_setting parses a percentage value (optionally with a trailing %) and requires the number to be within 10.0–100.0 inclusive. Non-numeric input and out-of-range values both raise this error with the 10–100 expectation stated. It guards percentage-style settings from invalid bounds.
Solutions
- Provide a number between 10 and 100, optionally with a trailing %
- Remove non-numeric characters except a decimal point and optional %
- If you intended a smaller value, check the setting's minimum is indeed 10
Example fix
// before set context_percent 5 // after set context_percent 10
Defensive patterns
Strategy: validation
Validate before calling
fn valid_percent(v: &str) -> bool {
match v.trim().trim_end_matches('%').trim().parse::<f64>() {
Ok(n) => (10.0..=100.0).contains(&n),
Err(_) => false,
}
} Try / catch
match parse_percent_setting(key, raw) {
Ok(p) => /* use p */,
Err(e) if e.to_string().contains("10 to 100") => {
eprintln!("{e}"); // clamp or prompt the user for 10-100
}
Err(e) => return Err(e),
} Prevention
- Validate the numeric range 10-100 before calling
- Allow but strip a trailing '%' if your UI supplies one
- Reject non-numeric input at the UI layer with immediate feedback
When it happens
Trigger: Setting a percentage setting with non-numeric text ("abc", "half") or a number below 10 or above 100, e.g. `/setting context_percent 5` or `150%`.
Common situations: Setting a percentage too low thinking 0–100 was allowed; typos like "1O" (letter O); pasting values with currency or other suffixes.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Failed to parse boolean
- Invalid ' ': expected
- context_window must be greater than 0
- CRON EXPR must have exactly 5 fields: minute hour…
- Failed to parse ONCE AT
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/91b756c6d7bf8720.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/settings.rs:2840
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();
let percent = trimmed.parse::<f64>().map_err(|_| {
anyhow::anyhow!(
"Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100."
)
})?;
if !(10.0..=100.0).contains(&percent) {
anyhow::bail!(
"Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100."
);
}
Ok(percent)
}
fn normalize_mention_menu_behavior(value: &str) -> Result<String> {
match value.trim().to_ascii_lowercase().as_str() {
"fuzzy" | "default" => Ok("fuzzy".to_string()),
"browser" | "browse" | "file-browser" | "file_browser" => Ok("browser".to_string()),
_ => {
anyhow::bail!(
"Failed to update setting: invalid mention_menu_behavior '{value}'. Expected: fuzzy, browser."
)
}
}
}
View on GitHub (pinned to 73e0f67d83)