{"record":{"id":"947c227a0f365c07","repo":"nautechsystems/nautilus_trader","slug":"failed-to-deserialize-msgpack-payload-e","errorCode":null,"errorMessage":"Failed to deserialize msgpack `payload`: {e}","messagePattern":"Failed to deserialize msgpack `payload`: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/queries.rs","lineNumber":115,"sourceCode":"            }\n            SerializationEncoding::Capnp => {\n                anyhow::bail!(\"Cap'n Proto encoding is not supported for Redis cache payloads\")\n            }\n        }\n    }\n\n    /// Deserializes the given byte slice `payload` into type `T` using the specified `encoding`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if deserialization from the chosen encoding fails or converting to the target type fails.\n    pub fn deserialize_payload<T: DeserializeOwned>(\n        encoding: SerializationEncoding,\n        payload: &[u8],\n    ) -> anyhow::Result<T> {\n        let mut value = match encoding {\n            SerializationEncoding::MsgPack => rmp_serde::from_slice(payload)\n                .map_err(|e| anyhow::anyhow!(\"Failed to deserialize msgpack `payload`: {e}\"))?,\n            SerializationEncoding::Json => serde_json::from_slice(payload)\n                .map_err(|e| anyhow::anyhow!(\"Failed to deserialize json `payload`: {e}\"))?,\n            SerializationEncoding::Sbe => {\n                anyhow::bail!(\"SBE encoding is not supported for Redis cache payloads\")\n            }\n            SerializationEncoding::Capnp => {\n                anyhow::bail!(\"Cap'n Proto encoding is not supported for Redis cache payloads\")\n            }\n        };\n\n        convert_timestamp_strings(&mut value);\n\n        serde_json::from_value(value)\n            .map_err(|e| anyhow::anyhow!(\"Failed to convert value to target type: {e}\"))\n    }\n\n    /// Scans Redis for keys matching the given `pattern`.\n    ///","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/queries.rs#L97-L133","documentation":"deserialize_payload decodes raw bytes back into T using rmp_serde::from_slice (MsgPack) or serde_json::from_slice (Json). This error wraps rmp_serde decode failures: the bytes are not valid msgpack or do not match the shape of T. SBE and Capnp are explicitly rejected before this branch.","triggerScenarios":"Calling deserialize_payload::<T>(SerializationEncoding::MsgPack, bytes) where bytes were not produced by serialize_payload with MsgPack, were truncated/corrupted, or encode a different type's shape than T.","commonSituations":"Reading Redis cache entries written by a different app version whose payload struct changed fields; decoding a JSON-encoded payload with the MsgPack encoding parameter; corrupted/truncated bytes fetched from Redis.","solutions":["Verify the encoding parameter matches the encoding used at write time (check the entry's `encoding` header).","Ensure the target type T matches the struct that was serialized (same crate version on reader and writer).","Inspect the raw bytes with rmp_serde::from_slice::<rmpv::Value> to diagnose the mismatch.","Re-write the affected cache entries after aligning versions."],"exampleFix":"// before: mismatched encoding\nlet v: MyType = deserialize_payload(SerializationEncoding::MsgPack, &bytes)?;\n// after: use the encoding recorded when the payload was written\nlet v: MyType = deserialize_payload(encoding_from_header, &bytes)?;","handlingStrategy":"try-catch","validationCode":"// confirm bytes are msgpack before typed decode\nlet probe: Result<rmpv::Value, _> = rmp_serde::from_slice(bytes);\nif probe.is_err() { return Err(\"payload is not valid msgpack\".into()); }","typeGuard":null,"tryCatchPattern":"match deserialize_payload::<MyType>(encoding, bytes) {\n    Ok(v) => use(v),\n    Err(e) if e.to_string().contains(\"Failed to deserialize\") => {\n        log::error!(\"payload shape/encoding mismatch: {e}\");\n        // fall back to default or re-fetch after version alignment\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Persist and honor the encoding header used at write time.","Keep reader and writer payload structs (and crate versions) in sync.","Guard against SBE/Capnp encodings, which are unsupported for Redis cache payloads."],"tags":["redis","deserialization","msgpack"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}