Hmbown/CodeWhale · error

invalid boolean

Error message

invalid boolean '{raw}'

What it means

parse_bool is the config parser's lenient boolean reader, accepting common truthy/falsy words (1/true/yes/on/enabled, 0/false/no/off/disabled, case-insensitive). Any other spelling is rejected so a typo never silently evaluates to false.

Solutions

  1. Set the value to one of the accepted words: 1, true, yes, on, enabled or 0, false, no, off, disabled (case-insensitive)
  2. Replace single-letter forms like y/n with yes/no
  3. Check the variable for stray quotes or characters: 'true' with literal quotes is invalid

Example fix

// before
CODEWHALE_FLAG='y'

// after
CODEWHALE_FLAG=yes
Defensive patterns

Strategy: validation

Validate before calling

const BOOL_WORDS: [&str; 10] = ["1","true","yes","on","enabled","0","false","no","off","disabled"];
fn is_valid_bool(raw: &str) -> bool {
    BOOL_WORDS.contains(&raw.trim().to_ascii_lowercase().as_str())
}

Type guard

fn as_config_bool(raw: &str) -> Option<bool> {
    match raw.trim().to_ascii_lowercase().as_str() {
        "1" | "true" | "yes" | "on" | "enabled" => Some(true),
        "0" | "false" | "no" | "off" | "disabled" => Some(false),
        _ => None,
    }
}

Try / catch

match result {
    Err(e) if e.to_string().starts_with("invalid boolean") => {
        eprintln!("use 1/true/yes/on/enabled or 0/false/no/off/disabled");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A config value (env var or settings string) that parse_bool reads contains an unrecognized word, e.g. "TRUE " with an unusual character, "y", "yeah", "2", "t", or a localized word like "ja"/"vrai".

Common situations: Setting an env flag to "Y"/"N" out of habit; typos like "ture" or "flase"; passing a number other than 0/1; quoting artifacts such as embedded whitespace handled differently than expected (note the parser trims, but inner quotes like "'true'" fail).

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


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/5f5e7d85b3fe5671. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/lib.rs:6562

    }
    std::fs::copy(&legacy, &primary)
        .context("failed to migrate config from deepseek to codewhale home")?;
    tracing::info!(
        "Migrated config from {} to {}",
        legacy.display(),
        primary.display()
    );
    Ok(Some(ConfigMigration {
        legacy_path: legacy,
        primary_path: primary,
    }))
}

fn parse_bool(raw: &str) -> Result<bool> {
    match raw.trim().to_ascii_lowercase().as_str() {
        "1" | "true" | "yes" | "on" | "enabled" => Ok(true),
        "0" | "false" | "no" | "off" | "disabled" => Ok(false),
        _ => bail!("invalid boolean '{raw}'"),
    }
}

fn parse_http_headers(raw: &str) -> Result<BTreeMap<String, String>> {
    let mut headers = BTreeMap::new();
    for pair in raw.trim().split(',') {
        let pair = pair.trim();
        if pair.is_empty() {
            continue;
        }
        let Some((name, value)) = pair.split_once('=') else {
            bail!("invalid header pair '{pair}', expected name=value");
        };
        let name = name.trim();
        let value = value.trim();
        if name.is_empty() {
            bail!("header name cannot be empty");
        }

View on GitHub (pinned to 73e0f67d83)