{"record":{"id":"aa53aedadc02075a","repo":"nautechsystems/nautilus_trader","slug":"cap-n-proto-encoding-is-not-supported-for-redis-ca","errorCode":null,"errorMessage":"Cap'n Proto encoding is not supported for Redis cache payloads","messagePattern":"Cap'n Proto encoding is not supported for Redis cache payloads","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/queries.rs","lineNumber":99,"sourceCode":"    ) -> anyhow::Result<Vec<u8>> {\n        match encoding {\n            SerializationEncoding::MsgPack => {\n                let mut value = serde_json::to_value(payload)?;\n                convert_timestamps(&mut value);\n                rmp_serde::to_vec(&value)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to serialize msgpack `payload`: {e}\"))\n            }\n            SerializationEncoding::Json => {\n                let mut value = serde_json::to_value(payload)?;\n                convert_timestamps(&mut value);\n                serde_json::to_vec(&value)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to serialize json `payload`: {e}\"))\n            }\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\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}\"))?,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/queries.rs#L81-L117","documentation":"serialize_payload in the Redis query/cache layer only implements MsgPack and Json serialization. Cap'n Proto is a recognized SerializationEncoding enum value but has no implementation in this code path, so the function bails immediately to prevent silently writing data in an unsupported format.","triggerScenarios":"Calling serialize_payload (or the Redis cache/query API accepting a SerializationSetting) with SerializationEncoding::Capnp — e.g. a RedisCacheDatabase configured with Capnp serialization.","commonSituations":"Sharing one serialization setting across integrations where Capnp is supported elsewhere but not in the Redis cache; misconfigured cache clients copied from other backends; assuming enum completeness means all encodings are implemented.","solutions":["Configure the Redis cache with SerializationEncoding::Json or MsgPack instead of Capnp.","Decouple the Redis client's serialization setting from Capnp-configured components.","If Capnp support is required, add the Capnp arm to serialize_payload in crates/infrastructure/src/redis/queries.rs.","Fail fast at construction time by validating that the configured encoding is Json or MsgPack."],"exampleFix":"// before\nlet settings = SerializationSettings { encoding: SerializationEncoding::Capnp, .. };\n// after\nlet settings = SerializationSettings { encoding: SerializationEncoding::Json, .. };","handlingStrategy":"validation","validationCode":"fn capnp_allowed_for_redis(e: SerializationEncoding) -> bool {\n    matches!(e, SerializationEncoding::MsgPack | SerializationEncoding::Json) // Capnp not implemented\n}\nassert!(capnp_allowed_for_redis(settings.encoding));","typeGuard":"fn cache_encodings() -> [SerializationEncoding; 2] {\n    [SerializationEncoding::MsgPack, SerializationEncoding::Json]\n}","tryCatchPattern":"match serialize_payload(&payload, &settings) {\n    Ok(bytes) => { /* store */ }\n    Err(e) if e.to_string().contains(\"Cap'n Proto\") => {\n        tracing::error!(\"Redis cache does not support Capnp; reconfigure to Json/MsgPack\");\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Treat Capnp/SBE as unsupported for the Redis cache until implemented.","Keep Redis cache serialization config separate from Capnp-configured components.","Validate the setting at startup with a clear configuration error."],"tags":["redis","serialization","unsupported-encoding","capnp"],"backgroundTag":"unsupported-operation","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"}