pola-rs/polars · error

The batch is not available

Error message

The batch is not available

What it means

StreamState::unwrap() panics when called on the Waiting variant. Waiting means the async/live stream is still open and simply has no batch available yet; calling unwrap there discards the distinction between 'no data yet' and 'data present' and panics.

Solutions

  1. Match on StreamState instead of unwrapping; handle Waiting by polling again or awaiting the next item
  2. Only call unwrap after the stream signalled readiness or completion
  3. Convert StreamState to an Option/Result and handle None explicitly
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/polars-arrow/src/io/ipc/read/stream.rs:83 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/02be06999d5545fd. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-arrow/src/io/ipc/read/stream.rs:83

/// just doesn't hold any data right now.
pub enum StreamState {
    /// A live stream without data
    Waiting,
    /// Next item in the stream
    Some(RecordBatchT<Box<dyn Array>>),
}

impl StreamState {
    /// Return the data inside this wrapper.
    ///
    /// # Panics
    ///
    /// If the `StreamState` was `Waiting`.
    pub fn unwrap(self) -> RecordBatchT<Box<dyn Array>> {
        if let StreamState::Some(batch) = self {
            batch
        } else {
            panic!("The batch is not available")
        }
    }
}

/// Reads the next item, yielding `None` if the stream is done,
/// and a [`StreamState`] otherwise.
fn read_next<R: Read + Seek>(
    reader: &mut R,
    metadata: &StreamMetadata,
    dictionaries: &mut Dictionaries,
    message_buffer: &mut Vec<u8>,
    projection: &Option<ProjectionInfo>,
    scratch: &mut Vec<u8>,
    checked: UnsafeBool,
) -> PolarsResult<Option<StreamState>> {
    // determine metadata length
    let mut meta_length: [u8; 4] = [0; 4];

View on GitHub (pinned to fe841f959e)