{"record":{"id":"f1dd7876aa6dba00","repo":"quickwit-oss/tantivy","slug":"buffer-should-be-empty","errorCode":null,"errorMessage":"buffer should be empty","messagePattern":"buffer should be empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/directory/managed_directory.rs","lineNumber":293,"sourceCode":"    }\n\n    fn open_read(&self, path: &Path) -> result::Result<FileSlice, OpenReadError> {\n        let file_slice = self.directory.open_read(path)?;\n        let (footer, reader) = Footer::extract_footer(file_slice)\n            .map_err(|io_error| OpenReadError::wrap_io_error(io_error, path.to_path_buf()))?;\n        footer.is_compatible()?;\n        Ok(reader)\n    }\n\n    fn open_write(&self, path: &Path) -> result::Result<WritePtr, OpenWriteError> {\n        self.register_file_as_managed(path)\n            .map_err(|io_error| OpenWriteError::wrap_io_error(io_error, path.to_path_buf()))?;\n        Ok(io::BufWriter::new(Box::new(FooterProxy::new(\n            self.directory\n                .open_write(path)?\n                .into_inner()\n                .map_err(|_| ())\n                .expect(\"buffer should be empty\"),\n        ))))\n    }\n\n    fn atomic_write(&self, path: &Path, data: &[u8]) -> io::Result<()> {\n        self.register_file_as_managed(path)?;\n        self.directory.atomic_write(path, data)\n    }\n\n    fn atomic_read(&self, path: &Path) -> result::Result<Vec<u8>, OpenReadError> {\n        self.directory.atomic_read(path)\n    }\n\n    fn delete(&self, path: &Path) -> result::Result<(), DeleteError> {\n        self.directory.delete(path)\n    }\n\n    fn exists(&self, path: &Path) -> Result<bool, OpenReadError> {\n        self.directory.exists(path)","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/directory/managed_directory.rs#L275-L311","documentation":"Fires at the end of ManagedDirectory::open_write. A fresh BufWriter wrapping the underlying writer must have an empty internal buffer; after into_inner() flushes and returns the raw writer, a Some(buffer) means buffered bytes were still pending — i.e. the flush into the inner writer failed silently or the writer was misused. This generic guard catches that corruption path rather than letting a partially written file proceed.","triggerScenarios":"Thrown at src/directory/managed_directory.rs:293 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Investigate why BufWriter::into_inner returned Err (typically an IO error during the final flush)","Ensure the underlying writer (FooterProxy) does not error on flush for this path","Surface the flush IO error to callers instead of discarding it with map_err(|_| ())"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}