{"record":{"id":"fa70ac95ef624725","repo":"atuinsh/atuin","slug":"trailing-bytes-in-encoded-kvrecord-malformed","errorCode":null,"errorMessage":"trailing bytes in encoded kvrecord. malformed","messagePattern":"trailing bytes in encoded kvrecord\\. malformed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin-kv/src/store/record.rs","lineNumber":56,"sourceCode":"            eyre!(\"{err:?}\")\n        }\n\n        match version {\n            RecordVersion::V0 => {\n                let mut bytes = decode::Bytes::new(&data.0);\n\n                let nfields = decode::read_array_len(&mut bytes).map_err(error_report)?;\n                ensure!(nfields == 3, \"too many entries in v0 kv record\");\n\n                let bytes = bytes.remaining_slice();\n\n                let (namespace, bytes) =\n                    decode::read_str_from_slice(bytes).map_err(error_report)?;\n                let (key, bytes) = decode::read_str_from_slice(bytes).map_err(error_report)?;\n                let (value, bytes) = decode::read_str_from_slice(bytes).map_err(error_report)?;\n\n                if !bytes.is_empty() {\n                    bail!(\"trailing bytes in encoded kvrecord. malformed\");\n                }\n\n                Ok(Self {\n                    namespace: namespace.to_owned(),\n                    key: key.to_owned(),\n                    value: Some(value.to_owned()),\n                })\n            }\n            RecordVersion::V1 => {\n                let mut bytes = decode::Bytes::new(&data.0);\n\n                let nfields = decode::read_array_len(&mut bytes).map_err(error_report)?;\n                ensure!(nfields == 4, \"too many entries in v1 kv record\");\n\n                let bytes = bytes.remaining_slice();\n\n                let (namespace, bytes) =\n                    decode::read_str_from_slice(bytes).map_err(error_report)?;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin-kv/src/store/record.rs#L38-L74","documentation":"Decoder guard in KvRecord::deserialize (V0 branch): after reading namespace, key, and optional value, bytes remain unconsumed. A valid v0 KV record ends exactly at its last field, so trailing bytes indicate a malformed record — corruption, truncation, or an encoder that wrote more fields than the decoder expects.","triggerScenarios":"Thrown at crates/atuin-kv/src/store/record.rs:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete and re-write the affected KV record, or re-sync the kv store","Check for disk corruption or interrupted writes","Reproduce with a fresh sync before reporting upstream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}