GitoxideLabs/gitoxide · error

Integers needs to be positive or negative numbers which may…

Error message

Integers needs to be positive or negative numbers which may have a suffix like 1k, 42, or 50G

What it means

gix-config-value's `Integer` parses git-config style integers: an optional sign followed by digits and an optional unit suffix ('k', 'm', 'g' — optionally with a multiplier like '1ki'). `int_err` builds this Error with the offending input when the string does not match that grammar. The error message text itself contains the known typo ('needs' spelled 'needs' as 'Integers needs').

Solutions

  1. Write the value as an integer with an optional k/m/g suffix, e.g. '1k', '42', '50G'
  2. Remove decimals, commas, spaces, or unknown characters from the value
  3. Catch the Error and fall back to a default numeric value

Example fix

// before (config)
[core]
    bigFileThreshold = 1,000k
// after
[core]
    bigFileThreshold = 1000k
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_git_int(s: &str) -> bool {
    let s = s.trim();
    let (digits, _) = if let Some(stripped) = s.strip_suffix(['k','m','g']) { (s.len()-stripped.len(), ()) } else { (s.len(), ()) };
    s.chars().take(digits).all(|c| c.is_ascii_digit() || c=='-' || c=='+') && !s.is_empty()
}

Try / catch

let n = Integer::try_from(value).map(|i| i.to_decimal()).transpose().unwrap_or(DEFAULT);

Prevention

When it happens

Trigger: `Integer::try_from(&BStr)` / `TryFrom<OsString>` with input like '1.5k' (decimals unsupported), 'k42' (suffix before digits), '10 x' (unknown suffix), or a purely alphabetic string.

Common situations: Config values such as `packSizeLimit = ~50M` or `bigFileThreshold = 1,000k` where the user used formatting (tilde, thousands separators, decimals) that git's integer syntax does not accept.

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/dd0096321ea48543. Report an issue: GitHub.

Appendix: source

Thrown at gix-config-value/src/integer.rs:51

    }
}

#[cfg(feature = "serde")]
impl serde::Serialize for Integer {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        if let Some(suffix) = self.suffix {
            serializer.serialize_i64(self.value << suffix.bitwise_offset())
        } else {
            serializer.serialize_i64(self.value)
        }
    }
}

fn int_err(input: impl Into<BString>) -> Error {
    Error::new(
        "Integers needs to be positive or negative numbers which may have a suffix like 1k, 42, or 50G",
        input,
    )
}

/// Parse `input` the way `git_parse_signed()` does, which hands the value to
/// `strtoimax()` with a base of `0`: an optional sign, then hexadecimal behind a `0x`
/// prefix, binary behind a `0b` prefix, octal behind a `0` prefix, and decimal otherwise.
fn parse_like_git(input: &str) -> Option<i64> {
    let (negative, rest) = match input.as_bytes().first() {
        Some(b'+') => (false, &input[1..]),
        Some(b'-') => (true, &input[1..]),
        _ => (false, input),
    };

    let Some(prefixed) = rest.strip_prefix('0') else {
        return input.parse().ok();
    };

View on GitHub (pinned to e73179060b)