{"record":{"id":"66244f73d8c95927","repo":"GitoxideLabs/gitoxide","slug":"booleans-need-to-be-no-off-false-or-y","errorCode":null,"errorMessage":"Booleans need to be 'no', 'off', 'false', '' or 'yes', 'on', 'true' or any number","messagePattern":"Booleans need to be 'no', 'off', 'false', '' or 'yes', 'on', 'true' or any number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-config-value/src/boolean.rs","lineNumber":8,"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","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-config-value/src/boolean.rs#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the config value to one of: 'no', 'off', 'false', '' or 'yes', 'on', 'true' or a number","Normalize/trim the string in your code before calling `try_from` (the parser does not trim whitespace)","Handle the Error and fall back to a default boolean instead of propagating it"],"exampleFix":"// before (config)\n[alias]\n    autosetup = maybe\n// after\n[alias]\n    autosetup = true","handlingStrategy":"validation","validationCode":"fn is_valid_git_bool(s: &str) -> bool {\n    matches!(s.trim(), \"no\"|\"off\"|\"false\"|\"\"|\"yes\"|\"on\"|\"true\") || s.trim().parse::<i64>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"let b = Boolean::try_from(value).unwrap_or(Boolean::new(false));","preventionTips":["Trim and lowercase config strings before parsing booleans","Validate user-edited config files at load time","Provide defaults with unwrap_or for optional flags"],"tags":["git","config","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"}