nautechsystems/nautilus_trader · error

Invalid type format: {stream_msg:?}

Error message

Invalid type format: {stream_msg:?}

What it means

When decoding the optional `type` header field, its value must be a BulkString. Any other value variant paired with the `type` key aborts decoding with this error, since the message type name cannot be read.

Source

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

    for pair in fields.as_chunks::<2>().0 {
        let redis::Value::BulkString(key) = &pair[0] else {
            anyhow::bail!("Invalid stream field key: {stream_msg:?}");
        };

        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;
            }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Fix the producer to write the type header as a UTF-8 string (e.g. 'data.TradeTick')
  2. Inspect the raw entry ({stream_msg:?}) to confirm the value variant under `type`
  3. Omit the `type` field entirely if the message is a legacy/custom payload — it is optional
  4. Delete the malformed entry (XDEL) to unblock the consumer
Defensive patterns

Strategy: validation

Validate before calling

fn type_header_ok(entry: &redis::Value) -> bool {
    matches!(entry, redis::Value::Array(f) if f.chunks(2).all(|c|
        !matches!(&c[0], redis::Value::BulkString(k) if k == b"type") || matches!(c[1], redis::Value::BulkString(_))))
}

Try / catch

match decode_bus_message(&entry) {
    Err(e) if e.to_string().contains("Invalid type format") => {
        log::warn!("bad type header, skipping entry: {e}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A stream entry with a `type` field whose value is not a byte string (Nil, Int, Array, etc.) — from a producer writing a non-string type header or corrupted/mock entry data.

Common situations: Custom or buggy producers serializing the type header incorrectly; test fixtures with wrong value variants; stream data written by a different tool with binary/odd encodings.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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