nautechsystems/nautilus_trader · error
Error parsing encoding: {e}
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.
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)
Solutions
- Dump the entry and fix the producer to emit UTF-8 encoding names (e.g. "msgpack", "json").
- Remove and republish the corrupt entry.
- 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
- Write encoding names through library constants only.
- Avoid manual XRADD with hand-built field bytes.
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
- Error parsing topic: {e}
- Error parsing type: {e}
- Error parsing payload kind: {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/6ec51bf24f967e43.
Report an issue: GitHub.