huggingface/candle · error
not a vec {v:?}
Error message
not a vec {v:?} What it means
Value::to_vec throws this when the metadata value is not an Array. Only Value::Array variants can be borrowed as a list of nested values; scalar or string values bail with this message, printing the actual variant. It signals you tried to iterate a non-list GGUF entry.
Source
Thrown at candle-core/src/quantized/gguf_file.rs:308
pub fn to_f64(&self) -> Result<f64> {
match self {
Self::F64(v) => Ok(*v),
v => crate::bail!("not a f64 {v:?}"),
}
}
pub fn to_bool(&self) -> Result<bool> {
match self {
Self::Bool(v) => Ok(*v),
v => crate::bail!("not a bool {v:?}"),
}
}
pub fn to_vec(&self) -> Result<&Vec<Value>> {
match self {
Self::Array(v) => Ok(v),
v => crate::bail!("not a vec {v:?}"),
}
}
pub fn to_string(&self) -> Result<&String> {
match self {
Self::String(v) => Ok(v),
v => crate::bail!("not a string {v:?}"),
}
}
fn read<R: std::io::Read + std::io::Seek>(
reader: &mut R,
value_type: ValueType,
magic: &VersionedMagic,
depth: usize,
file_size: u64,
) -> Result<Self> {
if depth > GGUF_MAX_VALUE_DEPTH {View on GitHub (pinned to d5fee525bf)
Solutions
- Call the accessor matching the printed variant (to_string for strings, to_u32 for numbers, ...).
- Check the Content metadata map for the correct list key name (e.g. tokenizer.ggml.tokens vs tokenizer.ggml.model).
- Match on Value::Array explicitly and skip/handle scalar entries when scanning all metadata.
- Rewrite the GGUF file with the field as an Array if it was wrongly written as a scalar.
Example fix
// before
let tokens = content.metadata.get("tokenizer.ggml.tokens").unwrap().to_vec()?;
// after
let tokens = match content.metadata.get("tokenizer.ggml.tokens") {
Some(gguf_file::Value::Array(vs)) => vs,
Some(other) => candle_core::bail!("tokens is not an array: {other:?}"),
None => candle_core::bail!("missing tokenizer.ggml.tokens"),
}; Defensive patterns
Strategy: type-guard
Validate before calling
fn is_array(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::Array(_)) }
if !is_array(value) { bail!("expected array metadata, got {value:?}"); } Type guard
fn as_array(v: &gguf_file::Value) -> Option<&Vec<gguf_file::Value>> {
if let gguf_file::Value::Array(vs) = v { Some(vs) } else { None }
} Try / catch
let arr = match value.to_vec() {
Ok(vs) => vs,
Err(e) => { eprintln!("not an array: {e}"); return Ok(Vec::new()); }
}; Prevention
- Verify GGUF key names (plural .tokens/.merges/.scores) before reading
- Handle scalar values when iterating all metadata entries
- Validate required list fields exist and are arrays right after Content::read
- Compare against a known-good file from the same converter
When it happens
Trigger: Calling .to_vec() on a scalar metadata entry such as 'tokenizer.ggml.model' (a String) or a numeric field, when the intent was a list like 'tokenizer.ggml.tokens'.
Common situations: Confusing similarly named GGUF keys (singular vs .tokens/.scores/.merges plural forms); files where a list field was collapsed to a single scalar by the writer; iterating all Content metadata and assuming every value is an array.
Related errors
- not a f32 {v:?}
- not a f64 {v:?}
- not a bool {v:?}
- not a string {v:?}
- multiple value-types in the same array {value_type:?}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/1f1395288513fc21.
Report an issue: GitHub.