nautechsystems/nautilus_trader · error

guarded above

Error message

guarded above

What it means

In `generate_order_status_report`, when a status command carries only a `client_order_id`, the adapter maps it to a Derive order label. Derive has no by-label lookup endpoint, so the code scans open orders and trigger orders. The `expect("guarded above")` asserts that an earlier match arm guaranteed `client_order_id` is Some by the time this branch runs; the panic indicates the guard and this branch have diverged.

Source

Thrown at crates/adapters/derive/src/execution.rs:776

                        .get_trigger_orders(&DeriveGetTriggerOrdersParams::new(subaccount_id))
                        .await?
                        .orders;

                    match trigger_orders
                        .into_iter()
                        .find(|o| o.order_id.as_str() == venue_order_id.as_str())
                    {
                        Some(order) => Some(order),
                        None => return Err(e.into()),
                    }
                }
            }
        } else {
            // Derive has no by-label lookup endpoint; scan open orders first,
            // then trigger orders, then fall through to paginated history so
            // terminal orders resolve for reconcilers that only carry the
            // client_order_id.
            let label = cmd.client_order_id.expect("guarded above");
            let open_orders = self
                .http_client
                .get_open_orders(&DeriveGetOpenOrdersParams::new(subaccount_id))
                .await?
                .orders;
            let mut found = open_orders.into_iter().find(|o| o.label == label.as_str());

            if found.is_none() {
                let trigger_orders = self
                    .http_client
                    .get_trigger_orders(&DeriveGetTriggerOrdersParams::new(subaccount_id))
                    .await?
                    .orders;
                found = trigger_orders
                    .into_iter()
                    .find(|o| o.label == label.as_str());
            }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Fix the guard earlier in the function so it checks exactly the same condition (client_order_id is Some) as this branch.
  2. Return a proper error (e.g. "order status requires client_order_id or venue_order_id") instead of panicking when neither ID is present.
  3. Log the full command when the expect would fire to identify which request shape bypassed the guard.
  4. Add a unit test covering status queries with only venue_order_id, only client_order_id, and neither.

Example fix

// before
let label = cmd.client_order_id.expect("guarded above");
// after
let Some(label) = cmd.client_order_id.as_ref() else {
    return Err(derive_error("order status requires a client_order_id"));
};
Defensive patterns

Strategy: validation

Validate before calling

let Some(label) = cmd.client_order_id.as_ref() else {
    return Err(/* order status requires client_order_id or venue_order_id */);
};

Prevention

When it happens

Trigger: Calling `generate_order_status_report` where control flow reaches the label-scan branch with `cmd.client_order_id == None` — i.e. the upstream guard checked a different field or a new command shape bypassed the guard (e.g. query by venue_order_id-only routed here incorrectly).

Common situations: Seen after refactoring the report-generation match arms, or when a reconciler sends a status request whose command variant slipped past the intended guard (order_id set instead of client_order_id).

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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