{"record":{"id":"dd0096321ea48543","repo":"GitoxideLabs/gitoxide","slug":"integers-needs-to-be-positive-or-negative-numbers","errorCode":null,"errorMessage":"Integers needs to be positive or negative numbers which may have a suffix like 1k, 42, or 50G","messagePattern":"Integers needs to be positive or negative numbers which may have a suffix like 1k, 42, or 50G","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-config-value/src/integer.rs","lineNumber":51,"sourceCode":"    }\n}\n\n#[cfg(feature = \"serde\")]\nimpl serde::Serialize for Integer {\n    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>\n    where\n        S: serde::Serializer,\n    {\n        if let Some(suffix) = self.suffix {\n            serializer.serialize_i64(self.value << suffix.bitwise_offset())\n        } else {\n            serializer.serialize_i64(self.value)\n        }\n    }\n}\n\nfn int_err(input: impl Into<BString>) -> Error {\n    Error::new(\n        \"Integers needs to be positive or negative numbers which may have a suffix like 1k, 42, or 50G\",\n        input,\n    )\n}\n\n/// Parse `input` the way `git_parse_signed()` does, which hands the value to\n/// `strtoimax()` with a base of `0`: an optional sign, then hexadecimal behind a `0x`\n/// prefix, binary behind a `0b` prefix, octal behind a `0` prefix, and decimal otherwise.\nfn parse_like_git(input: &str) -> Option<i64> {\n    let (negative, rest) = match input.as_bytes().first() {\n        Some(b'+') => (false, &input[1..]),\n        Some(b'-') => (true, &input[1..]),\n        _ => (false, input),\n    };\n\n    let Some(prefixed) = rest.strip_prefix('0') else {\n        return input.parse().ok();\n    };","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-config-value/src/integer.rs#L33-L69","documentation":"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').","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Write the value as an integer with an optional k/m/g suffix, e.g. '1k', '42', '50G'","Remove decimals, commas, spaces, or unknown characters from the value","Catch the Error and fall back to a default numeric value"],"exampleFix":"// before (config)\n[core]\n    bigFileThreshold = 1,000k\n// after\n[core]\n    bigFileThreshold = 1000k","handlingStrategy":"validation","validationCode":"fn is_valid_git_int(s: &str) -> bool {\n    let s = s.trim();\n    let (digits, _) = if let Some(stripped) = s.strip_suffix(['k','m','g']) { (s.len()-stripped.len(), ()) } else { (s.len(), ()) };\n    s.chars().take(digits).all(|c| c.is_ascii_digit() || c=='-' || c=='+') && !s.is_empty()\n}","typeGuard":null,"tryCatchPattern":"let n = Integer::try_from(value).map(|i| i.to_decimal()).transpose().unwrap_or(DEFAULT);","preventionTips":["Ban decimals, thousands separators and spaces in numeric config values","Document accepted suffixes (k/m/g) in user-facing docs","Sanitize numeric config input at write time"],"tags":["git","config","integer","parsing"],"backgroundTag":"invalid-config-value","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}