{"record":{"id":"dd4ef2dfe8eeeffc","repo":"huggingface/candle","slug":"not-a-bool-v","errorCode":null,"errorMessage":"not a bool {v:?}","messagePattern":"not a bool (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/gguf_file.rs","lineNumber":301,"sourceCode":"\n    pub fn to_f32(&self) -> Result<f32> {\n        match self {\n            Self::F32(v) => Ok(*v),\n            v => crate::bail!(\"not a f32 {v:?}\"),\n        }\n    }\n\n    pub fn to_f64(&self) -> Result<f64> {\n        match self {\n            Self::F64(v) => Ok(*v),\n            v => crate::bail!(\"not a f64 {v:?}\"),\n        }\n    }\n\n    pub fn to_bool(&self) -> Result<bool> {\n        match self {\n            Self::Bool(v) => Ok(*v),\n            v => crate::bail!(\"not a bool {v:?}\"),\n        }\n    }\n\n    pub fn to_vec(&self) -> Result<&Vec<Value>> {\n        match self {\n            Self::Array(v) => Ok(v),\n            v => crate::bail!(\"not a vec {v:?}\"),\n        }\n    }\n\n    pub fn to_string(&self) -> Result<&String> {\n        match self {\n            Self::String(v) => Ok(v),\n            v => crate::bail!(\"not a string {v:?}\"),\n        }\n    }\n\n    fn read<R: std::io::Read + std::io::Seek>(","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/gguf_file.rs#L283-L319","documentation":"Value::to_bool throws this when the GGUF metadata value is not the Bool variant. GGUF booleans are a distinct tagged type; candle will not interpret e.g. a u8 or string as a boolean. The offending value is printed with Debug formatting in the message.","triggerScenarios":"Calling .to_bool() on a metadata entry stored as U8 (some GGUF writers encode flags as u8 0/1), or on any String/Array entry, e.g. a 'tokenizer.ggml.add_bos_token' flag written as u8.","commonSituations":"Reading GGUF files produced by writers that predate or ignore the bool value type and use u8 flags; assuming custom metadata fields are bools without checking the type; copy-pasted accessor code from another field.","solutions":["Check the error's {v:?} and use the correct accessor — for a u8 flag, test .to_u8() != 0.","Match on the Value enum and treat Value::U8(1)/Value::Bool(true) as true.","Fix the GGUF writer to emit ValueType::Bool for this field.","Reject the file during pre-validation if a required field must be a strict bool."],"exampleFix":"// before\nlet add_bos = value.to_bool()?;\n// after\nlet add_bos = match value {\n    gguf_file::Value::Bool(b) => b,\n    gguf_file::Value::U8(b) => b != 0,\n    other => candle_core::bail!(\"unexpected add_bos flag {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_bool(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::Bool(_)) }\nif !is_bool(value) { bail!(\"expected bool metadata, got {value:?}\"); }","typeGuard":"fn as_bool(v: &gguf_file::Value) -> Option<bool> {\n    match v {\n        gguf_file::Value::Bool(b) => Some(*b),\n        gguf_file::Value::U8(b) => Some(*b != 0),\n        _ => None,\n    }\n}","tryCatchPattern":"let b = match value {\n    gguf_file::Value::Bool(b) => b,\n    other => { eprintln!(\"flag not bool: {other:?}\"); false }\n};","preventionTips":["Treat u8 flags as potential bools when reading files from varied producers","Inspect Value::value_type() before choosing an accessor","Keep a schema of expected key->type for the architectures you support","Reject files whose required flag fields are not the expected type"],"tags":["candle","gguf","type-mismatch"],"backgroundTag":"unexpected-value-type","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}