{"record":{"id":"20510d12e8359cf8","repo":"pola-rs/polars","slug":"file-to-have-ended","errorCode":null,"errorMessage":"File to have ended","messagePattern":"File to have ended","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-parquet/src/parquet/write/file.rs","lineNumber":262,"sourceCode":"            None,\n        );\n\n        let len = end_file(&mut self.writer, &metadata)?;\n        self.state = State::Finished;\n        self.metadata = Some(metadata);\n        Ok(self.offset + len)\n    }\n\n    /// Returns the underlying writer.\n    pub fn into_inner(self) -> W {\n        self.writer\n    }\n\n    /// Returns the underlying writer and [`ThriftFileMetadata`]\n    /// # Panics\n    /// This function panics if [`Self::end`] has not yet been called\n    pub fn into_inner_and_metadata(self) -> (W, ThriftFileMetadata) {\n        (self.writer, self.metadata.expect(\"File to have ended\"))\n    }\n}\n","sourceCodeStart":244,"sourceCodeEnd":265,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-parquet/src/parquet/write/file.rs#L244-L265","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet (w, meta) = writer.into_inner_and_metadata(); // panics: end() not called\n\n// after\nwriter.end(None)?;\nlet (w, meta) = writer.into_inner_and_metadata();","handlingStrategy":"validation","validationCode":"// end() is the validator: its Ok proves metadata exists\nwriter.end(None)?;\nlet (w, meta) = writer.into_inner_and_metadata();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["parquet","writer","api-misuse","panic","rust"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}