{"record":{"id":"0328e44f2ddd40a9","repo":"huggingface/candle","slug":"unexpected-bool-value-b","errorCode":null,"errorMessage":"unexpected bool value {b}","messagePattern":"unexpected bool value (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/gguf_file.rs","lineNumber":343,"sourceCode":"    ) -> Result<Self> {\n        if depth > GGUF_MAX_VALUE_DEPTH {\n            crate::bail!(\"gguf: value nesting depth exceeds max {GGUF_MAX_VALUE_DEPTH}\")\n        }\n        let v = match value_type {\n            ValueType::U8 => Self::U8(reader.read_u8()?),\n            ValueType::I8 => Self::I8(reader.read_i8()?),\n            ValueType::U16 => Self::U16(reader.read_u16::<LittleEndian>()?),\n            ValueType::I16 => Self::I16(reader.read_i16::<LittleEndian>()?),\n            ValueType::U32 => Self::U32(reader.read_u32::<LittleEndian>()?),\n            ValueType::I32 => Self::I32(reader.read_i32::<LittleEndian>()?),\n            ValueType::U64 => Self::U64(reader.read_u64::<LittleEndian>()?),\n            ValueType::I64 => Self::I64(reader.read_i64::<LittleEndian>()?),\n            ValueType::F32 => Self::F32(reader.read_f32::<LittleEndian>()?),\n            ValueType::F64 => Self::F64(reader.read_f64::<LittleEndian>()?),\n            ValueType::Bool => match reader.read_u8()? {\n                0 => Self::Bool(false),\n                1 => Self::Bool(true),\n                b => crate::bail!(\"unexpected bool value {b}\"),\n            },\n            ValueType::String => Self::String(read_string(reader, magic, file_size)?),\n            ValueType::Array => {\n                let value_type = reader.read_u32::<LittleEndian>()?;\n                let value_type = ValueType::from_u32(value_type)?;\n                let len = read_length(reader, magic)?;\n                if len > GGUF_MAX_ARRAY_ELEMENTS {\n                    crate::bail!(\"gguf: array length {len} exceeds max {GGUF_MAX_ARRAY_ELEMENTS}\")\n                }\n                let needed = len.saturating_mul(value_type.min_disk_size(magic));\n                let remaining = remaining_bytes(reader, file_size)?;\n                if needed > remaining {\n                    crate::bail!(\n                        \"gguf: array of {len} elements needs at least {needed} bytes, only {remaining} remaining\"\n                    )\n                }\n                let mut vs = Vec::new();\n                for _ in 0..len {","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/gguf_file.rs#L325-L361","documentation":"GGUF encodes booleans as a single byte that must be exactly 0 or 1; Value::read throws this when the byte is anything else. The parser refuses to coerce other byte values (e.g. 2, 0xFF) to a bool. This indicates a corrupted, truncated, or non-conforming file since a valid GGUF writer never emits other bytes.","triggerScenarios":"Reading a GGUF file where a Bool-typed metadata value contains a byte other than 0 or 1 — caused by file corruption, a broken writer, or a desynchronized read stream after earlier parse errors.","commonSituations":"Partial downloads or truncated model files; custom/older GGUF writers encoding bools differently (e.g. as u32); reading a stream positioned at the wrong offset after a previous field was mis-parsed.","solutions":["Re-download or re-export the GGUF file — the bytes do not conform to the GGUF spec.","Check file size/integrity (checksum) before parsing.","If your own writer produced it, emit exactly 0x00 or 0x01 for ValueType::Bool.","If reading from a non-seekable stream, ensure no earlier read misaligned the position."],"exampleFix":"// before\nlet flag = content.metadata.get(\"my.flag\"); // parse already failed upstream\n// after (writer side)\n// before\nw.write_u32::<LittleEndian>(flag as u32)?;\n// after\nw.write_u8(if flag { 1 } else { 0 })?;","handlingStrategy":"validation","validationCode":"// verify integrity before parse\nlet digest = sha256_hex(File::open(path)?)?;\nif digest != EXPECTED_SHA256 { bail!(\"GGUF file corrupt: bool byte invalid\"); }","typeGuard":null,"tryCatchPattern":"match gguf_file::Content::read(&mut reader) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"unexpected bool value\") => {\n        eprintln!(\"corrupt GGUF (non-0/1 bool byte), re-download\");\n        return Err(Error::Msg(\"corrupt gguf\".into()));\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Checksum files after download and before parsing","Ensure any custom GGUF writer emits exactly 0x00/0x01 for Bool","Detect truncated downloads via expected file size","Re-sync/seek the reader to a known offset after any parse error"],"tags":["candle","gguf","corrupt-file","encoding"],"backgroundTag":"malformed-file-data","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}