nautechsystems/nautilus_trader · error
failed to decode SBE {type_name}: {e}
Error message
failed to decode SBE {type_name}: {e} What it means
Raised by deserialize_payload in the SBE codec when T::from_sbe fails to decode a byte payload into the target type. The error wraps the underlying SBE decoding error with the message type name, indicating the payload is not a valid SBE encoding of that type (wrong type, bad schema version, or corrupt data).
Source
Thrown at crates/common/src/msgbus/external/codec/sbe.rs:32
// -------------------------------------------------------------------------------------------------
use std::any::Any;
use bytes::Bytes;
use nautilus_model::data::{
Bar, FundingRateUpdate, IndexPriceUpdate, MarkPriceUpdate, OptionGreeks, OrderBookDeltas,
OrderBookDepth10, QuoteTick, TradeTick,
};
use nautilus_serialization::sbe::{FromSbe, ToSbe};
use super::PayloadCodecError;
use crate::msgbus::BusPayloadType;
fn deserialize_payload<T>(payload: &[u8], type_name: &str) -> anyhow::Result<T>
where
T: FromSbe,
{
T::from_sbe(payload).map_err(|e| anyhow::anyhow!("failed to decode SBE {type_name}: {e}"))
}
macro_rules! define_deserializer {
($fn_name:ident, $ty:ty, $type_name:literal) => {
pub(crate) fn $fn_name(payload: &[u8]) -> anyhow::Result<$ty> {
deserialize_payload::<$ty>(payload, $type_name)
}
};
}
define_deserializer!(
deserialize_order_book_deltas,
OrderBookDeltas,
"OrderBookDeltas"
);
define_deserializer!(
deserialize_order_book_depth10,
OrderBookDepth10,View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure the payload was encoded with the matching SBE encoder for the same message type.
- Align SBE schema versions between the producing and consuming sides.
- Verify payload completeness and integrity end-to-end (no truncation or corruption).
- Regenerate the SBE codecs from the current schema if message definitions changed.
Defensive patterns
Strategy: try-catch
Try / catch
match sbe_deserialize_quote_tick(payload) {
Ok(tick) => handle(tick),
Err(e) if e.to_string().contains("failed to decode SBE") => {
log::warn!("dropping undecodable SBE payload: {e:#}");
// verify encoder schema version / dead-letter the message
}
Err(e) => return Err(e),
} Prevention
- Encode and decode with codecs generated from the same SBE schema version.
- Include a message type tag in the transport framing so payloads reach the right deserializer.
- Add round-trip encode/decode tests for every SBE message type.
- Verify payload length/framing before decoding to catch truncation early.
When it happens
Trigger: Calling a generated SBE deserializer with bytes that were not encoded by the corresponding SBE encoder; schema version mismatch between encoder and decoder; truncated or corrupted payloads.
Common situations: Publisher and consumer built against different message schemas; manually routing messages to the wrong codec; network or queue corruption; mixed nautilus versions exchanging SBE frames.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to decode Cap'n Proto {}: {}
- Wrong template ID: expected {balance_update_event_codec::SBE
- Unsupported SBE execution type: {et}
- Unsupported SBE order side: {side}
- Cap'n Proto decoding requires the `capnp` feature
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/b9bc2dd760612e2b.
Report an issue: GitHub.