{"record":{"id":"240dadb2d46d601f","repo":"janhq/jan","slug":"error-reading-metadata-entry","errorCode":null,"errorMessage":"Error reading metadata entry {}: {}","messagePattern":"Error reading metadata entry (.+?): (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":30,"sourceCode":"    if &magic != b\"GGUF\" {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"Not a GGUF file\",\n        ));\n    }\n\n    let version = file.read_u32::<LittleEndian>()?;\n    let tensor_count = file.read_u64::<LittleEndian>()?;\n    let metadata_count = file.read_u64::<LittleEndian>()?;\n\n    let mut metadata_map = std::collections::HashMap::new();\n    for i in 0..metadata_count {\n        match read_metadata_entry(&mut file, i) {\n            Ok((key, value)) => {\n                metadata_map.insert(key, value);\n            }\n            Err(e) => {\n                return Err(io::Error::new(\n                    io::ErrorKind::InvalidData,\n                    format!(\"Error reading metadata entry {}: {}\", i, e),\n                ));\n            }\n        }\n    }\n\n    Ok(GgufMetadata {\n        version,\n        tensor_count,\n        metadata: metadata_map,\n    })\n}\n\nfn read_metadata_entry<R: Read + Seek + ReadBytesExt>(\n    reader: &mut R,\n    index: u64,\n) -> io::Result<(String, String)> {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L12-L48","documentation":"Wraps any error produced while reading the i-th metadata key/value pair inside the metadata loop. The function iterates `metadata_count` entries and, on failure of `read_metadata_entry`, re-wraps the underlying error as `InvalidData` with the entry index for diagnostics. It is a generic aggregator — the root cause lives one level deeper (key read, value-type decode, or value read).","triggerScenarios":"Any structural corruption of the metadata kv-array: a truncated file cutting off mid-entry, a bad string length inside an entry, an unknown value-type discriminator, or an oversized array inside a metadata value. Also fires when `metadata_count` itself was misread (e.g. a 32-bit vs 64-bit length mismatch) so the loop walks past real data into garbage.","commonSituations":"Truncated GGUF download that parses the header fine but ends before all metadata entries are present; an editor or transport that mangled binary bytes; a non-standard quantized file whose metadata layout differs from what this parser expects. The index reported tells you how many entries parsed cleanly before failure.","solutions":["Read the inner error message — it names the specific cause (key read, value type, value read); address that first.","Verify file integrity with `sha256sum` against the published checksum to rule out truncation/corruption.","If the index is small and consistent across files of the same model family, suspect a value-type or layout mismatch in `read_gguf_value`; otherwise suspect file corruption.","Re-download the model from a trusted source if checksum mismatch indicates corruption."],"exampleFix":"// before\nmatch read_metadata_entry(&mut file, i) {\n    Ok((k, v)) => { metadata_map.insert(k, v); }\n    Err(e) => return Err(io::Error::new(InvalidData, format!(\"Error reading metadata entry {}: {}\", i, e))),\n}\n\n// after - surface inner kind + byte offset for diagnostics\nmatch read_metadata_entry(&mut file, i) {\n    Ok((k, v)) => { metadata_map.insert(k, v); }\n    Err(e) => {\n        let pos = file.stream_position().unwrap_or(0);\n        return Err(io::Error::new(InvalidData,\n            format!(\"metadata entry {} failed at byte {}: {}\", i, pos, e)));\n    }\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"match read_gguf_metadata(reader) {\n    Ok(m) => Ok(m),\n    Err(e) if e.to_string().contains(\"Error reading metadata entry\") => {\n        tracing::error!(\"GGUF metadata truncated/corrupt: {e}\");\n        Err(InvalidModel(e.to_string()))\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Verify file checksums before parsing to catch truncation/corruption early.","Log the failing entry index so users can correlate with hex-dump output.","Quarantine unparseable files and continue batch processing."],"tags":["gguf","metadata","parsing","llamacpp","rust"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}