Skip to content

Ensure error reporting when using buffered file writes #9102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tronical
Copy link
Member

@tronical tronical commented Aug 8, 2025

Quoting from the BufWriter docs:

It is critical to call flush before BufWriter is dropped. Though
dropping will attempt to flush the contents of the buffer, any errors
that happen in the process of dropping will be ignored. Calling flush
ensures that the buffer is empty and thus dropping will not even
attempt file operations.

Quoting from the BufWriter docs:

>It is critical to call flush before BufWriter<W> is dropped. Though
>dropping will attempt to flush the contents of the buffer, any errors
>that happen in the process of dropping will be ignored. Calling flush
>ensures that the buffer is empty and thus dropping will not even
>attempt file operations.
write!(&mut BufWriter::new(std::fs::File::create(&cpp_file_name)?), "{cpp_file}")?;
let mut cpp_writer = BufWriter::new(std::fs::File::create(&cpp_file_name)?);
write!(&mut cpp_writer, "{cpp_file}")?;
cpp_writer.flush()?;
Copy link
Contributor

@ubruhin ubruhin Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually BufWriter could even be removed here I guess, as the whole file is written at once(?) Same applies to two other locations. EDIT: Hmm well maybe I'm wrong, I don't know exactly what's the type of cpp_file and how it gets written to the stream.

And btw, in my fork I still have the patch from #9092 included, so what I've actually tested is the combination of those two changes. Generally I'd still vote to implement the atomic file writes as long as there's no serious drawback (I didn't check the details about it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants