nautechsystems/nautilus_trader · error

Invalid index key format: {key}

Error message

Invalid index key format: {key}

What it means

Key-format guard in get_index_key: Redis index keys must either contain the ':index:' delimiter (instance-prefixed form) or start with 'index:'; anything else is not a recognizable index key and is rejected.

Source

Thrown at crates/infrastructure/src/redis/mod.rs:51

const REDIS_INDEX_PATTERN: &str = ":index:";
const REDIS_XTRIM: &str = "XTRIM";
const REDIS_MINID: &str = "MINID";
const REDIS_FLUSHDB: &str = "FLUSHDB";

/// Extracts the index key from a full Redis key.
///
/// Handles keys with `instance_id` prefix by finding the `:index:` pattern.
/// For example, `trader-id:uuid:index:order_position` -> `index:order_position`.
pub(crate) fn get_index_key(key: &str) -> anyhow::Result<&str> {
    if let Some(pos) = key.find(REDIS_INDEX_PATTERN) {
        return Ok(&key[pos + 1..]);
    }

    if key.starts_with("index:") {
        return Ok(key);
    }

    anyhow::bail!("Invalid index key format: {key}")
}

async fn await_handle(handle: Option<tokio::task::JoinHandle<()>>, task_name: &str) {
    if let Some(handle) = handle {
        log_task_awaiting(task_name);

        let timeout = Duration::from_secs(2);
        match tokio::time::timeout(timeout, handle).await {
            Ok(result) => {
                if let Err(e) = result {
                    log::error!("Error awaiting task '{task_name}': {e:?}");
                }
            }
            Err(_) => {
                log::warn!("Timeout {timeout:?} awaiting task '{task_name}'");
            }
        }
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass keys produced by the index write path
  2. Prefix the key with the instance id and ':index:' or use the bare 'index:...' form
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/infrastructure/src/redis/mod.rs:51 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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