nautechsystems/nautilus_trader · error

Error parsing encoding

Error message

Error parsing encoding: {e}

What it means

The `encoding` header of a stream entry must be valid UTF-8 before it is parsed into a SerializationEncoding. This error wraps the FromUtf8Error/Utf8Error from decoding the raw bytes. It is distinct from error 4005, which is the parse failure into the encoding enum.

Solutions

  1. Dump the entry and fix the producer to emit UTF-8 encoding names (e.g. "msgpack", "json").
  2. Remove and republish the corrupt entry.
  3. Audit any custom publisher for correct string encoding.
Defensive patterns

Strategy: try-catch

Validate before calling

if std::str::from_utf8(&encoding_bytes).is_err() {
    return Err("encoding header is not UTF-8".into());
}

Try / catch

match decode_bus_message(entry) {
    Ok(m) => handle(m),
    Err(e) if e.to_string().contains("Error parsing encoding") => log::warn!("bad encoding header, skipping entry"),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: stream_messages -> decode_bus_message encounters an `encoding` field whose BulkString bytes are not valid UTF-8.

Common situations: Binary corruption of the header; a producer writing non-text bytes into the encoding field; manual stream manipulation.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/6ec51bf24f967e43. Report an issue: GitHub.

Appendix: source

Thrown at crates/infrastructure/src/redis/msgbus.rs:863

            }
            key if key == PAYLOAD_KIND_FIELD.as_bytes() => {
                let redis::Value::BulkString(bytes) = &pair[1] else {
                    anyhow::bail!("Invalid payload kind format: {stream_msg:?}");
                };
                let value = std::str::from_utf8(bytes)
                    .map_err(|e| anyhow::anyhow!("Error parsing payload kind: {e}"))?;
                anyhow::ensure!(
                    value == PAYLOAD_KIND_TYPED,
                    "Unknown payload kind '{value}'"
                );
                typed_payload = true;
            }
            b"encoding" => {
                let redis::Value::BulkString(bytes) = &pair[1] else {
                    anyhow::bail!("Invalid encoding format: {stream_msg:?}");
                };
                let value = std::str::from_utf8(bytes)
                    .map_err(|e| anyhow::anyhow!("Error parsing encoding: {e}"))?;
                encoding = value
                    .parse()
                    .map_err(|e| anyhow::anyhow!("Error parsing encoding: {e}"))?;
            }
            b"payload" => {
                let redis::Value::BulkString(bytes) = &pair[1] else {
                    anyhow::bail!("Invalid payload format: {stream_msg:?}");
                };
                payload = Some(Bytes::copy_from_slice(bytes));
            }
            _ => {}
        }
    }

    let Some(topic) = topic else {
        anyhow::bail!("Stream message missing topic: {stream_msg:?}");
    };
    let Some(payload) = payload else {

View on GitHub (pinned to 18893faf8b)