nautechsystems/nautilus_trader · error

Invalid data element not `Bar`, was {data:?}

Error message

Invalid data element not `Bar`, was {data:?}

What it means

In `get_range_bars`, each decoded record must decode to `Some(Data::Bar)`. If decoding yields `None` or any non-bar `Data` variant, the match falls to the catch-all arm and bails. This means the record stream for a bar request did not contain bar data.

Source

Thrown at crates/adapters/databento/src/historical.rs:835

                &instrument_id,
                price_precision_arg,
                &mut precision_cache,
            )?;

            let (data, _) = decode_record(
                &record,
                instrument_id,
                price_precision,
                None,
                false, // Not applicable
                timestamp_on_close,
            )?;

            match data {
                Some(Data::Bar(bar)) => {
                    result.push(bar);
                }
                _ => anyhow::bail!("Invalid data element not `Bar`, was {data:?}"),
            }
        }

        Ok(result)
    }

    /// Fetches imbalance data for the given parameters.
    ///
    /// # Errors
    ///
    /// Returns an error if the API request or data processing fails.
    pub async fn get_range_imbalance(
        &self,
        params: RangeQueryParams,
    ) -> anyhow::Result<Vec<DatabentoImbalance>> {
        let symbols: Vec<&str> = params.symbols.iter().map(String::as_str).collect();
        check_consistent_symbology(&symbols)?;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the aggregation maps to the intended OHLCV schema (Ohlcv1S/1M/1H/1D).
  2. Inspect the `{data:?}` value in the message to see what was actually decoded.
  3. Ensure the dataset/publisher actually serves OHLCV data for the requested instrument.
  4. Align the databento-rs DBN version with the one this adapter was built against.

Example fix

// before
// schema resolved to trades but called get_range_bars
let bars = client.get_range_bars(&params, BarAggregation::Minute)?;
// after
params.schema = Some("ohlcv-1m");
let bars = client.get_range_bars(&params, BarAggregation::Minute)?;
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the request is actually a bar request before decoding
assert params.schema.startswith("ohlcv"), f"bar fetch requires ohlcv schema, got {params.schema}"

Prevention

When it happens

Trigger: Calling `get_range_bars` when the resolved schema is not an OHLCV schema, or the record fails to decode into a bar (e.g. a trade/quote record reaching the bar decode path, or None from decode_record).

Common situations: Schema/aggregation mismatch causing trade records to enter the bar pipeline; datasets or record types unsupported by the decoder; Databento SDK version change altering record decoding.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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