pola-rs/polars · error
File to have ended
Error message
File to have ended
What it means
ParquetFileWriter::into_inner_and_metadata returns the thrift FileMetaData that is only populated by end(), which writes the footer and sets self.metadata. Calling it before a successful end() finds metadata == None and panics with 'File to have ended'. The panic is documented in the rustdoc of the method.
Source
Thrown at crates/polars-parquet/src/parquet/write/file.rs:262
None,
);
let len = end_file(&mut self.writer, &metadata)?;
self.state = State::Finished;
self.metadata = Some(metadata);
Ok(self.offset + len)
}
/// Returns the underlying writer.
pub fn into_inner(self) -> W {
self.writer
}
/// Returns the underlying writer and [`ThriftFileMetadata`]
/// # Panics
/// This function panics if [`Self::end`] has not yet been called
pub fn into_inner_and_metadata(self) -> (W, ThriftFileMetadata) {
(self.writer, self.metadata.expect("File to have ended"))
}
}
View on GitHub (pinned to df599052da)
Solutions
- Call end(key_value_metadata) and propagate its Result before into_inner_and_metadata()
- If end() returned Err, treat the writer as failed — use into_inner() to recover the underlying writer, not the metadata API
- Only use into_inner_and_metadata() in code paths where end() has provably succeeded
Example fix
// before let (w, meta) = writer.into_inner_and_metadata(); // panics: end() not called // after writer.end(None)?; let (w, meta) = writer.into_inner_and_metadata();
Defensive patterns
Strategy: validation
Validate before calling
// end() is the validator: its Ok proves metadata exists writer.end(None)?; let (w, meta) = writer.into_inner_and_metadata();
Prevention
- Treat end() as a mandatory finalizer with ?-propagation
- Never call into_inner_and_metadata() on error paths
- Use into_inner() when metadata is not required
When it happens
Trigger: Calling writer.into_inner_and_metadata() without calling writer.end(...) first, or ignoring an Err returned by end() (e.g. footer write failed) and then unwrapping metadata anyway.
Common situations: Custom Parquet sinks that finish writing row groups and forget the footer step; error paths where end() failed (disk full, IO error) and cleanup code still asks for metadata.
Related errors
- expr expected, did you call when().then().otherwise?
- invalid `POLARS_MAX_CACHED_METADATA_SCANS` value
- integer
- not implemented
- not implemented
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/20510d12e8359cf8.
Report an issue: GitHub.