{"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/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-parquet/src/parquet/write/file.rs#L244-L265","documentation":"into_inner_and_metadata returns the writer plus ThriftFileMetadata, but the metadata is Some only after end() ran; calling it before end() makes metadata.expect(\"File to have ended\") panic, i.e. the file writer was still mid-stream.","triggerScenarios":"Calling into_inner_and_metadata() on a FileWriter before finish/end() has serialized the footer metadata.","commonSituations":"Early-return paths in sink implementations skipping the finalize step; error handling that abandons the writer then tries to reclaim the inner writer via this method; forgetting the explicit end() call in custom write loops.","solutions":["Call writer.end() (and propagate its Result) before into_inner_and_metadata","If abandoning the file due to an error, drop the writer instead of extracting metadata","Ensure finalize runs even on early returns (scopeguard/cleanup)"],"exampleFix":"// before\nlet (w, meta) = writer.into_inner_and_metadata(); // panics\n// after\nwriter.end(&mut dynamics)?;\nlet (w, meta) = writer.into_inner_and_metadata();","handlingStrategy":"validation","validationCode":"// Rust: only extract after successful finalize\nlet (writer, meta) = match writer.end(&mut dynamics) {\n    Ok(()) => writer.into_inner_and_metadata(),\n    Err(e) => return Err(e),\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call end() before into_inner_and_metadata (documented contract)","Use scopeguard to finalize or explicitly drop writers on error paths","Keep finalize logic in a single helper"],"tags":["parquet","writer","invalid-state","finalize"],"backgroundTag":"invalid-state-transition","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}