Hmbown/CodeWhale · error
Invalid ' ': expected
Error message
Invalid {key} '{value}': expected {min}-{max} What it means
parse_u16_range parses a settings value as a u16 and requires it to fall within [min, max]. Failure to parse as an integer, or an out-of-range result, both produce this error naming the key and accepted range. It is numeric validation for bounded u16 settings.
Solutions
- Supply a plain unsigned integer within the stated min-max range (no decimals, percent signs, or units)
- Check the setting's documented range and adjust the value
- Trim whitespace around the value
Example fix
// before set preview_lines 12.5 // after set preview_lines 12
Defensive patterns
Strategy: validation
Validate before calling
fn valid_u16_in(v: &str, min: u16, max: u16) -> bool {
v.trim().parse::<u16>().map(|n| (min..=max).contains(&n)).unwrap_or(false)
} Try / catch
match parse_setting_u16(key, raw, 1, 100) {
Ok(n) => /* use n */,
Err(e) if e.to_string().contains("Invalid") => {
eprintln!("{e}"); // message already states the accepted range
}
Err(e) => return Err(e),
} Prevention
- Strip units/symbols (% etc.) before parsing
- Validate integers with parse::<u16>() client-side first
- Look up each setting's documented min/max before assigning
When it happens
Trigger: Setting a u16-bounded setting with a non-integer ("abc", "12.5") or a value outside the key's [min,max] window, e.g. `/setting preview_lines 99999` when max is lower.
Common situations: Typos and fat-fingering ranges; pasting a float or suffixed value ("50%"); not knowing the valid range for the setting.
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 update setting: invalid
- context_window must be greater than 0
- CRON EXPR must have exactly 5 fields: minute hour…
- Failed to parse boolean
- Failed to parse ONCE AT
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/ff8a8ed83793743a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/settings.rs:2827
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();
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)
}View on GitHub (pinned to 73e0f67d83)