GitoxideLabs/gitoxide · error

Booleans need to be 'no', 'off', 'false', '' or 'yes'…

Error message

Booleans need to be 'no', 'off', 'false', '' or 'yes', 'on', 'true' or any number

What it means

gix-config-value's `Boolean` type only accepts the git-config boolean spellings: 'no', 'off', 'false', '' (empty), 'yes', 'on', 'true', or a bare number (any non-zero number is true, 0 is false). `bool_err` builds this Error with the offending input embedded whenever parsing falls through all of those cases. It is thrown from the `TryFrom<&BStr>` / `TryFrom<OsString>` conversions that callers use to read a boolean out of git configuration.

Solutions

  1. Fix the config value to one of: 'no', 'off', 'false', '' or 'yes', 'on', 'true' or a number
  2. Normalize/trim the string in your code before calling `try_from` (the parser does not trim whitespace)
  3. Handle the Error and fall back to a default boolean instead of propagating it

Example fix

// before (config)
[alias]
    autosetup = maybe
// after
[alias]
    autosetup = true
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_git_bool(s: &str) -> bool {
    matches!(s.trim(), "no"|"off"|"false"|""|"yes"|"on"|"true") || s.trim().parse::<i64>().is_ok()
}

Try / catch

let b = Boolean::try_from(value).unwrap_or(Boolean::new(false));

Prevention

When it happens

Trigger: Calling `Boolean::try_from(&BStr)` or `Boolean::try_from(OsString)` with input that is none of the accepted literals: e.g. `"maybe"`, `"TRUE "` (whitespace not stripped by caller), `"enabled"`, or misspelled values read from a config file.

Common situations: Users hand-editing `.git/config` or `~/.gitconfig` type something like `publishMaybe = maybe` or `flag = onn`; tooling then reads the key via gix and gets this error instead of silently defaulting.

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 GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/66244f73d8c95927. Report an issue: GitHub.

Appendix: source

Thrown at gix-config-value/src/boolean.rs:8

use std::{borrow::Cow, ffi::OsString, fmt::Display};

use bstr::{BStr, BString, ByteSlice};

use crate::{Boolean, Error};

fn bool_err(input: impl Into<BString>) -> Error {
    Error::new(
        "Booleans need to be 'no', 'off', 'false', '' or 'yes', 'on', 'true' or any number",
        input,
    )
}

impl TryFrom<OsString> for Boolean {
    type Error = Error;

    fn try_from(value: OsString) -> Result<Self, Self::Error> {
        let value = gix_path::os_str_into_bstr(&value)
            .map_err(|_| Error::new("Illformed UTF-8", std::path::Path::new(&value).display().to_string()))?;
        Self::try_from(value)
    }
}

/// # Warning
///
/// The direct usage of `try_from("string")` is discouraged as it will produce the wrong result for values

View on GitHub (pinned to e73179060b)