{"record":{"id":"7fd586c5e2b1fbe3","repo":"nautechsystems/nautilus_trader","slug":"invalid-encoding-format-stream-msg","errorCode":null,"errorMessage":"Invalid encoding format: {stream_msg:?}","messagePattern":"Invalid encoding format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/msgbus.rs","lineNumber":860,"sourceCode":"                    String::from_utf8(bytes.clone())\n                        .map_err(|e| anyhow::anyhow!(\"Error parsing type: {e}\"))?,\n                );\n            }\n            key if key == PAYLOAD_KIND_FIELD.as_bytes() => {\n                let redis::Value::BulkString(bytes) = &pair[1] else {\n                    anyhow::bail!(\"Invalid payload kind format: {stream_msg:?}\");\n                };\n                let value = std::str::from_utf8(bytes)\n                    .map_err(|e| anyhow::anyhow!(\"Error parsing payload kind: {e}\"))?;\n                anyhow::ensure!(\n                    value == PAYLOAD_KIND_TYPED,\n                    \"Unknown payload kind '{value}'\"\n                );\n                typed_payload = true;\n            }\n            b\"encoding\" => {\n                let redis::Value::BulkString(bytes) = &pair[1] else {\n                    anyhow::bail!(\"Invalid encoding format: {stream_msg:?}\");\n                };\n                let value = std::str::from_utf8(bytes)\n                    .map_err(|e| anyhow::anyhow!(\"Error parsing encoding: {e}\"))?;\n                encoding = value\n                    .parse()\n                    .map_err(|e| anyhow::anyhow!(\"Error parsing encoding: {e}\"))?;\n            }\n            b\"payload\" => {\n                let redis::Value::BulkString(bytes) = &pair[1] else {\n                    anyhow::bail!(\"Invalid payload format: {stream_msg:?}\");\n                };\n                payload = Some(Bytes::copy_from_slice(bytes));\n            }\n            _ => {}\n        }\n    }\n\n    let Some(topic) = topic else {","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/msgbus.rs#L842-L878","documentation":"The optional `encoding` header must be a BulkString containing a value parseable into SerializationEncoding. A non-BulkString value raises this error before the parse step (a bad string value would instead produce 'Error parsing encoding').","triggerScenarios":"A stream entry with an `encoding` field whose value is not a byte string (Nil, Int, etc.) — from a producer writing a non-string encoding header or corrupted/mock entry data.","commonSituations":"Producers from a different library version writing the header differently; custom pipelines stamping binary or numeric encoding markers; hand-crafted stream entries in tests.","solutions":["Write the encoding header as a string the SerializationEncoding parser accepts (e.g. 'json' or 'msgpack')","Omit the encoding field to use the default encoding (SerializationEncoding::default())","Align producer and consumer versions so the encoding header format matches","Inspect the raw entry and XDEL the malformed one to unblock the stream consumer"],"exampleFix":"// before\nredis.xadd(stream, \"*\", &[(\"encoding\", 2)]);\n// after\nredis.xadd(stream, \"*\", &[(\"encoding\", \"json\")]);","handlingStrategy":"validation","validationCode":"fn encoding_header_ok(entry: &redis::Value) -> bool {\n    matches!(entry, redis::Value::Array(f) if f.chunks(2).all(|c|\n        !matches!(&c[0], redis::Value::BulkString(k) if k == b\"encoding\") || matches!(c[1], redis::Value::BulkString(_))))\n}","typeGuard":null,"tryCatchPattern":"match decode_bus_message(&entry) {\n    Err(e) if e.to_string().contains(\"Invalid encoding format\") => {\n        log::warn!(\"bad encoding header, skipping entry: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Write encoding as a parseable string (e.g. \"json\") or omit it for the default","Validate encoding strings at the producer with value.parse::<SerializationEncoding>()","Share header constants between producer and consumer code"],"tags":["redis","deserialization","validation"],"backgroundTag":"type-mismatch","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"}