nautechsystems/nautilus_trader · error · anyhow::Error

Cap'n Proto decoding requires the `capnp` feature

Error message

Cap'n Proto decoding requires the `capnp` feature

What it means

This module is a compile-time placeholder used when the crate is built without the `capnp` feature. Every generated Cap'n Proto deserializer stub unconditionally fails with this error, because decoding Cap'n Proto payloads requires the feature-gated implementation.

Source

Thrown at crates/common/src/msgbus/external/codec/capnp_unavailable.rs:30

//  See the License for the specific language governing permissions and
//  limitations under the License.
// -------------------------------------------------------------------------------------------------

use std::any::Any;

use bytes::Bytes;
use nautilus_model::data::{
    Bar, FundingRateUpdate, IndexPriceUpdate, MarkPriceUpdate, OptionGreeks, OrderBookDeltas,
    OrderBookDepth10, QuoteTick, TradeTick,
};

use super::PayloadCodecError;
use crate::msgbus::BusPayloadType;

macro_rules! define_deserializer {
    ($fn_name:ident, $ty:ty) => {
        pub(crate) fn $fn_name(_payload: &[u8]) -> anyhow::Result<$ty> {
            anyhow::bail!("Cap'n Proto decoding requires the `capnp` feature")
        }
    };
}

define_deserializer!(deserialize_order_book_deltas, OrderBookDeltas);
define_deserializer!(deserialize_order_book_depth10, OrderBookDepth10);
define_deserializer!(deserialize_quote, QuoteTick);
define_deserializer!(deserialize_trade, TradeTick);
define_deserializer!(deserialize_bar, Bar);
define_deserializer!(deserialize_mark_price, MarkPriceUpdate);
define_deserializer!(deserialize_index_price, IndexPriceUpdate);
define_deserializer!(deserialize_funding_rate, FundingRateUpdate);
define_deserializer!(deserialize_option_greeks, OptionGreeks);

pub(super) fn serialize_payload(
    payload_type: BusPayloadType,
    _message: &dyn Any,
) -> Result<Bytes, PayloadCodecError> {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Rebuild with the `capnp` feature enabled, e.g. `cargo build --features capnp` (or add it to your Cargo.toml dependency features list).
  2. If capnp cannot be enabled, switch the external sender/publisher to a supported codec (e.g. JSON/msgpack) so payloads match the built features.
  3. Verify at startup which codecs the binary supports and reject capnp stream configuration early.
  4. Check that your deployment pipeline preserves feature flags used in development builds.

Example fix

// before (Cargo.toml)
nautilus-common = "0.x"
// after
nautilus-common = { version = "0.x", features = ["capnp"] }
Defensive patterns

Strategy: fallback

Try / catch

let deltas = match decode_deltas(payload) {
    Ok(d) => d,
    Err(e) if e.to_string().contains("capnp") => {
        eprintln!("capnp codec unavailable; use a JSON/msgpack publisher or rebuild with --features capnp");
        return Err(e);
    }
    Err(e) => return Err(e),
};

Prevention

When it happens

Trigger: Receiving or decoding a Cap'n Proto-encoded external bus payload (order book deltas, depth10, etc.) while the crate was compiled without the `capnp` feature enabled.

Common situations: Installing a prebuilt package or default `cargo build` that omits non-default features, then connecting to an external sender that emits capnp-encoded payloads; feature flags dropped when switching from a source build to a packaged build.

Related errors


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