{"record":{"id":"0dcb3cee71b8ed32","repo":"janhq/jan","slug":"failed-to-read-key-for-metadata-entry","errorCode":null,"errorMessage":"Failed to read key for metadata entry {}: {}","messagePattern":"Failed to read key for metadata entry (.+?): (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":50,"sourceCode":"                    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)> {\n    let key = read_gguf_string(reader).map_err(|e| {\n        io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"Failed to read key for metadata entry {}: {}\", index, e),\n        )\n    })?;\n\n    let value_type_u32 = reader.read_u32::<LittleEndian>()?;\n    let value_type = GgufValueType::try_from(value_type_u32)?;\n    let value = read_gguf_value(reader, value_type)?;\n\n    Ok((key, value))\n}\n\nfn read_gguf_string<R: Read + ReadBytesExt>(reader: &mut R) -> io::Result<String> {\n    let len = reader.read_u64::<LittleEndian>()?;\n    if len > (1024 * 1024) {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"String length {} is unreasonably large\", len),","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L32-L68","documentation":"Returned by `read_metadata_entry` when `read_gguf_string` fails on the entry's key. A metadata key is encoded as a u64 little-endian length followed by that many UTF-8 bytes; this error fires if the length read fails (EOF), the length is unreasonable (see error 83), the byte read fails, or the bytes are not valid UTF-8. The wrapper adds the entry index so the caller knows which key broke.","triggerScenarios":"A metadata kv entry whose key length field is unparseable (file truncated at the length field), whose declared length exceeds 1 MiB, or whose bytes are not UTF-8 (e.g. a binary blob mistaken for a key). Also fires if the previous value read consumed the wrong number of bytes, leaving the stream misaligned at the next key.","commonSituations":"Misaligned stream after an array value was skipped with the wrong stride; truncated download; a quantized GGUF produced by a tool whose key encoding differs. The error message itself includes the inner cause (e.g. \"unreasonably large\" or a Utf8Error) which pinpoints the sub-failure.","solutions":["Inspect the inner error: \"unreasonably large\" points to misalignment/corruption; a Utf8Error points to non-text bytes; EOF points to truncation.","If misalignment is suspected (e.g. after a skipped array), audit `skip_array_data` against the GGUF spec for the offending element type.","Re-verify the file checksum and re-download if corrupted.","Try a different GGUF of the same architecture to determine if the bug is file-specific or parser-specific."],"exampleFix":"// before\nlet key = read_gguf_string(reader).map_err(|e| io::Error::new(InvalidData,\n    format!(\"Failed to read key for metadata entry {}: {}\", index, e)))?;\n\n// after - log reader position before the failing read\nlet pos = reader.stream_position().unwrap_or(0);\nlet key = read_gguf_string(reader).map_err(|e| io::Error::new(InvalidData,\n    format!(\"key read failed at entry {} (byte {}): {}\", index, pos, e)))?;","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(\"Failed to read key\") => {\n        Err(InvalidModel(format!(\"metadata key read failed: {e}\")))\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Treat key-read failures as corruption signals and verify checksums.","Log the stream position to help localize misalignment.","Keep a known-good reference GGUF to distinguish file bugs from parser bugs."],"tags":["gguf","metadata","string","parsing","llamacpp","rust"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}