quickwit-oss/tantivy · error

Failed to downcast collector fruit.

Error message

Failed to downcast collector fruit.

What it means

Fires in FruitHandle::extract when the boxed fruit at this handle's position in MultiFruit cannot be downcast to the requested TFruit type. Each handle is handed out by MultiCollector next to a collector whose fruit type it matches, so a mismatch means the caller is extracting with a fruit type that differs from the collector the handle was created for, or handles are mixed between two MultiCollector runs. The doc comment explicitly notes it can panic on faulty code.

Source

Thrown at src/collector/multi_collector.rs:120

}

/// FruitHandle stores reference to the corresponding collector inside MultiCollector
pub struct FruitHandle<TFruit: Fruit> {
    pos: usize,
    _phantom: PhantomData<TFruit>,
}

impl<TFruit: Fruit> FruitHandle<TFruit> {
    /// Extract a typed fruit off a multifruit.
    ///
    /// This function involves downcasting and can panic if the multifruit was
    /// created using faulty code.
    pub fn extract(self, fruits: &mut MultiFruit) -> TFruit {
        let boxed_fruit = fruits.sub_fruits[self.pos].take().expect("");
        *boxed_fruit
            .downcast::<TFruit>()
            .map_err(|_| ())
            .expect("Failed to downcast collector fruit.")
    }
}

/// Multicollector makes it possible to collect on more than one collector.
/// It should only be used for use cases where the Collector types is unknown
/// at compile time.
///
/// If the type of the collectors is known, you can just group yours collectors
/// in a tuple. See the
/// [Combining several collectors section of the collector
/// documentation](./index.html#combining-several-collectors).
///
/// ```rust
/// use tantivy::collector::{Count, TopDocs, MultiCollector};
/// use tantivy::query::QueryParser;
/// use tantivy::schema::{Schema, TEXT};
/// use tantivy::{doc, Index};
///

View on GitHub (pinned to b5d8deb80c)

Solutions

  1. Extract each fruit with exactly the fruit type of the collector at the handle's position
  2. Do not reuse FruitHandle values across different MultiCollector executions
  3. Prefer using the tuple-collector API where fruit types are checked at compile time
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/collector/multi_collector.rs:120 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of quickwit-oss/tantivy@b5d8deb80c (2026-09-05). Data as JSON: /api/errors/58317cbdeb26313e. Report an issue: GitHub.