{"record":{"id":"63ff670cfc965fee","repo":"GitoxideLabs/gitoxide","slug":"illformed-utf-8","errorCode":null,"errorMessage":"Illformed UTF-8","messagePattern":"Illformed UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-config-value/src/boolean.rs","lineNumber":19,"sourceCode":"use std::{borrow::Cow, ffi::OsString, fmt::Display};\n\nuse bstr::{BStr, BString, ByteSlice};\n\nuse crate::{Boolean, Error};\n\nfn bool_err(input: impl Into<BString>) -> Error {\n    Error::new(\n        \"Booleans need to be 'no', 'off', 'false', '' or 'yes', 'on', 'true' or any number\",\n        input,\n    )\n}\n\nimpl TryFrom<OsString> for Boolean {\n    type Error = Error;\n\n    fn try_from(value: OsString) -> Result<Self, Self::Error> {\n        let value = gix_path::os_str_into_bstr(&value)\n            .map_err(|_| Error::new(\"Illformed UTF-8\", std::path::Path::new(&value).display().to_string()))?;\n        Self::try_from(value)\n    }\n}\n\n/// # Warning\n///\n/// The direct usage of `try_from(\"string\")` is discouraged as it will produce the wrong result for values\n/// obtained from `core.bool-implicit-true`, which have no separator and are implicitly true.\n/// This method chooses to work correctly for `core.bool-empty=`, which is an empty string and resolves\n/// to being `false`.\n///\n/// Instead of this, obtain booleans with `config.boolean(…)`, which handles the case were no separator is\n/// present correctly.\nimpl TryFrom<&BStr> for Boolean {\n    type Error = Error;\n\n    fn try_from(value: &BStr) -> Result<Self, Self::Error> {\n        if parse_true(value) {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-config-value/src/boolean.rs#L1-L37","documentation":"`TryFrom<OsString> for Boolean` first converts the OS string into a `&BStr` via `gix_path::os_str_into_bstr`; when that conversion fails (the OS string is not representable as the byte string form, e.g. non-UTF-8 path-like data on some platforms) the code raises this Error labeled 'Illformed UTF-8' with the display form of the original value. It is a pre-parse failure, before boolean syntax is even examined.","triggerScenarios":"`Boolean::try_from(os_string)` where `os_string` comes from an environment variable, command-line argument, or file path that contains bytes that cannot be converted (e.g. non-UTF-8 Windows/OsStr data).","commonSituations":"Config values sourced from raw OS strings on platforms where `OsStr` is not UTF-8 internally (Windows WTF-16), or shell arguments containing invalid UTF-8 bytes.","solutions":["Sanitize or reject non-UTF-8 input before calling `Boolean::try_from(OsString)`","Convert the input to a `&BStr` yourself from known-good bytes (`BStr::new(&bytes)`) and use the `TryFrom<&BStr>` path","Catch the Error and report which value was ill-formed to the user"],"exampleFix":"// before\nlet b = Boolean::try_from(os_value)?;\n// after\nlet b = match std::str::from_utf8(os_value.as_bytes()) {\n    Ok(s) => Boolean::try_from(BStr::new(s))?,\n    Err(_) => return Err(/* report ill-formed UTF-8 input */),\n};","handlingStrategy":"type-guard","validationCode":"std::str::from_utf8(os_value.as_bytes()).map_err(|_| /* ill-formed UTF-8 */)?;","typeGuard":"fn is_utf8(v: &OsStr) -> bool { std::str::from_utf8(v.as_bytes()).is_ok() }","tryCatchPattern":"match Boolean::try_from(os_value) { Ok(b) => b, Err(e) => { log::warn!(\"invalid boolean input: {e}\"); Boolean::default() } }","preventionTips":["Reject non-UTF-8 inputs at the boundary (CLI/env) before they reach config parsing","Convert to BStr from trusted bytes when the source encoding is known","Log the offending input for diagnostics"],"tags":["git","config","utf-8","encoding"],"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"}