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

  1. Ensure the payload was encoded with the matching SBE encoder for the same message type.
  2. Align SBE schema versions between the producing and consuming sides.
  3. Verify payload completeness and integrity end-to-end (no truncation or corruption).
  4. 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

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.

Related errors


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