nautechsystems/nautilus_trader · error

Failed to parse funding rate record: {e}

Error message

Failed to parse funding rate record: {e}

What it means

The Tardis CSV funding-rate stream parser wraps any per-record parse failure from the CSV reader into an anyhow error so the stream yields a typed error item. The underlying CSV record did not match the expected funding-rate schema (missing/malformed columns, bad types). The original reader error is preserved in `{e}`.

Source

Thrown at crates/adapters/tardis/src/csv/stream.rs:1727

                    match result {
                        Ok(Some(funding_rate)) => {
                            self.buffer.push(funding_rate);
                            records_read += 1;
                            self.records_processed += 1;

                            if let Some(limit) = self.limit
                                && self.records_processed >= limit
                            {
                                break;
                            }
                        }
                        Ok(None) => {
                            // Skip this record as it has no funding data
                            self.records_processed += 1;
                        }
                        Err(e) => {
                            return Some(Err(anyhow::anyhow!(
                                "Failed to parse funding rate record: {e}"
                            )));
                        }
                    }
                }
                Ok(false) => {
                    if self.buffer.is_empty() {
                        return None;
                    }
                    let chunk = self.buffer.split_off(0);
                    return Some(Ok(chunk));
                }
                Err(e) => return Some(Err(anyhow::anyhow!("Failed to read record: {e}"))),
            }
        }

        if self.buffer.is_empty() {
            None

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Re-download the CSV from Tardis to rule out truncation/corruption.
  2. Inspect the message's inner `{e}` to find the offending column and compare the row against the expected funding-rate header schema.
  3. Check whether the Tardis CSV schema for the exchange changed and update the adapter/parser accordingly.
  4. Skip or quarantine the offending file and continue with valid data if only one record set is bad.

Example fix

// before: error is opaque upstream
return Some(Err(anyhow::anyhow!("Failed to parse funding rate record: {e}")));
// after: include row context for diagnosability
return Some(Err(anyhow::anyhow!(
    "Failed to parse funding rate record at line {}: {e}",
    self.records_processed + 1
)));
Defensive patterns

Strategy: validation

Validate before calling

// Validate header and row shape before streaming
let headers = reader.headers()?.clone();
assert!(headers.contains("funding_rate"), "unexpected funding CSV schema: {:?}", headers);

Try / catch

match stream.next() {
    Some(Ok(chunk)) => process(chunk),
    Some(Err(e)) if e.to_string().contains("Failed to parse funding rate record") => {
        log::warn!("skipping bad funding CSV: {e}");
    }
    Some(Err(e)) => return Err(e),
    None => break,
}

Prevention

When it happens

Trigger: Streaming a Tardis CSV funding rate file whose rows deviate from the expected schema: wrong column count, non-numeric funding rate/timestamp fields, malformed or missing values in a record.

Common situations: Downloading funding rate CSVs for an exchange whose Tardis schema changed; truncated or corrupted download; hand-edited files; requesting data from an instrument type the parser doesn't expect.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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