Hmbown/CodeWhale · error
Failed to parse boolean
Error message
Failed to parse boolean '{value}': expected on/off, true/false, yes/no. What it means
parse_bool accepts a fixed set of truthy/falsy spellings (on/off, true/false, yes/no, 1/0, enabled/disabled, case-insensitive). Any other string fails with this error. It is a user-input validation failure for boolean settings values.
Solutions
- Use one of the accepted values: on/off, true/false, yes/no, 1/0, enabled/disabled (case-insensitive)
- Trim surrounding whitespace and remove stray characters from the value
- Check the setting name is actually boolean before assigning it
Example fix
// before set foo_bar enable // after set foo_bar enabled
Defensive patterns
Strategy: validation
Validate before calling
const BOOLS: [&str; 10] = ["on","true","yes","1","enabled","off","false","no","0","disabled"];
fn valid_bool(v: &str) -> bool { BOOLS.contains(&v.trim().to_lowercase().as_str()) } Try / catch
match parse_setting_bool(raw) {
Ok(b) => /* use b */,
Err(e) if e.to_string().contains("Failed to parse boolean") => {
eprintln!("{e}; pass on/off, true/false, yes/no, 1/0, enabled/disabled");
}
Err(e) => return Err(e),
} Prevention
- Normalize input to lowercase and trim whitespace before passing
- Map your app's own truthy words ("y", "t", "enable") to accepted values first
- Never pass empty or interpolated-unset variables as boolean settings
When it happens
Trigger: Setting a boolean setting via the settings command/file with a value outside the accepted list, e.g. `/setting some_bool maybe`, `true ` with odd wording like "enable" or "on!".
Common situations: Typing synonyms not in the list ("enable", "y", "t"); copy-pasting values with extra words; script passing an unset variable producing an empty or garbage value.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
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 ONCE AT
- Failed to update setting
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/2eb416195f55ffa5.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/settings.rs:2800
trimmed.to_ascii_lowercase().as_str(),
"default" | "(default)" | "config" | "configured" | "unset"
)
{
return Ok(None);
}
ReasoningEffort::parse_strict(trimmed)
.map(|effort| Some(effort.as_setting().to_string()))
.map_err(|err| anyhow::anyhow!("Failed to update setting: {err}"))
}
/// Parse a boolean value from various formats
fn parse_bool(value: &str) -> Result<bool> {
match value.to_lowercase().as_str() {
"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."
)
})View on GitHub (pinned to 73e0f67d83)