nautechsystems/nautilus_trader · error

Error parsing type: {e}

Error message

Error parsing type: {e}

What it means

decode_bus_message requires the `type` field of a Redis stream entry to be a BulkString holding valid UTF-8 text naming the payload type. If the bytes fail String::from_utf8, this error wraps the FromUtf8Error. The type name is later resolved via BusPayloadType::from_name/from_typed_name.

Source

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

        };

        match key.as_slice() {
            b"topic" => {
                let redis::Value::BulkString(bytes) = &pair[1] else {
                    anyhow::bail!("Invalid topic format: {stream_msg:?}");
                };
                topic = Some(
                    String::from_utf8(bytes.clone())
                        .map_err(|e| anyhow::anyhow!("Error parsing topic: {e}"))?,
                );
            }
            b"type" => {
                let redis::Value::BulkString(bytes) = &pair[1] else {
                    anyhow::bail!("Invalid type format: {stream_msg:?}");
                };
                type_name = Some(
                    String::from_utf8(bytes.clone())
                        .map_err(|e| anyhow::anyhow!("Error parsing type: {e}"))?,
                );
            }
            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:?}");
                };

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Dump the stream entry and confirm the `type` bytes; fix the producer to emit UTF-8 strings.
  2. Check for version skew between publishers and subscribers writing different header encodings.
  3. Remove/re-publish the corrupt entry.
  4. If writing a custom producer, mirror the Nautilus msgbus header encoding (UTF-8 BulkStrings).
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: stream_messages -> decode_bus_message encounters a stream entry whose `type` field bytes are not valid UTF-8.

Common situations: Binary garbage written by a buggy producer into the `type` header; custom clients using a different text encoding; corrupted stream data after a Redis persistence/restore issue.

Related errors


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