nautechsystems/nautilus_trader · error
Error parsing payload kind: {e}
Error message
Error parsing payload kind: {e} What it means
The optional `payload_kind` header (PAYLOAD_KIND_FIELD) must decode as valid UTF-8 so it can be compared against PAYLOAD_KIND_TYPED. This error is thrown when the bytes are not valid UTF-8. (A well-formed but unrecognized kind value raises the separate 'Unknown payload kind' error instead.)
Source
Thrown at crates/infrastructure/src/redis/msgbus.rs:851
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:?}");
};
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 {View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the entry's payload_kind bytes and fix the producer to write the literal UTF-8 marker used by PAYLOAD_KIND_TYPED.
- Align producer/consumer versions so both use the same payload-kind convention.
- Delete the corrupt entry and republish.
Defensive patterns
Strategy: try-catch
Validate before calling
if std::str::from_utf8(&kind_bytes).is_err() {
return Err("payload_kind 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 payload kind") => log::warn!("corrupt payload_kind, skipping"),
Err(e) => return Err(e),
} Prevention
- Only set payload_kind via the library constants, never hand-written strings.
- Keep producer and consumer crate versions aligned.
When it happens
Trigger: decode_bus_message (via stream_messages) reads a `payload_kind` BulkString whose bytes fail std::str::from_utf8.
Common situations: A producer wrote raw/binary data into the payload_kind header; custom or older publishers emitting non-UTF-8 kind markers; stream corruption.
Related errors
- Error parsing topic: {e}
- Error parsing type: {e}
- Error parsing encoding: {e}
- Invalid payload format: {stream_msg:?}
- Stream message missing topic: {stream_msg:?}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/7800ee2c29fcb30e.
Report an issue: GitHub.