{"record":{"id":"1bd55f3fee3936d6","repo":"huggingface/candle","slug":"not-a-string-v","errorCode":null,"errorMessage":"not a string {v:?}","messagePattern":"not a string (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/gguf_file.rs","lineNumber":315,"sourceCode":"\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>(\n        reader: &mut R,\n        value_type: ValueType,\n        magic: &VersionedMagic,\n        depth: usize,\n        file_size: u64,\n    ) -> 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>()?),","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/gguf_file.rs#L297-L333","documentation":"Value::to_string throws this when the GGUF metadata value is not the String variant. GGUF strings are a distinct tagged type (with their own length prefix), and candle will not stringify other variants implicitly. The Debug form of the found value appears in the message.","triggerScenarios":"Calling .to_string() on a metadata entry stored as U8/U32/I64/Array etc., e.g. expecting 'general.architecture' to be a string but grabbing a numeric or array-valued key instead.","commonSituations":"Wrong metadata key lookup returning a numeric field; assuming byte-array tokens are strings when they are Arrays of u32; using to_string() on Value out of habit because Rust's ToString exists.","solutions":["Read the actual variant from the {v:?} output and use its accessor (to_u32, to_vec, ...).","Verify the metadata key name — a misspelled or renamed key may resolve to a differently typed entry.","Match on the Value enum and convert manually (e.g. format integer variants if a string display is wanted).","Fix the GGUF producer to write the field with ValueType::String."],"exampleFix":"// before\nlet arch = value.to_string()?;\n// after\nlet arch = match value {\n    gguf_file::Value::String(s) => s.as_str(),\n    other => candle_core::bail!(\"general.architecture is not a string: {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_string(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::String(_)) }\nif !is_string(value) { bail!(\"expected string metadata, got {value:?}\"); }","typeGuard":"fn as_str(v: &gguf_file::Value) -> Option<&str> {\n    if let gguf_file::Value::String(s) = v { Some(s.as_str()) } else { None }\n}","tryCatchPattern":"let s = match value.to_string() {\n    Ok(s) => s.clone(),\n    Err(e) => { eprintln!(\"not a string: {e}\"); return Err(e.into()); }\n};","preventionTips":["Don't confuse Rust's ToString with GGUF's to_string (which asserts the String variant)","Print the Debug value on mismatch to discover the actual variant","Lock metadata key names against the GGUF spec for the architecture","Fail fast with a clear message instead of silently coercing types"],"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"}