-
-
Notifications
You must be signed in to change notification settings - Fork 949
fix(oxfmt): handle WouldBlock when writing to stdout
#17943
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,16 +39,43 @@ pub fn read_to_string(path: &Path) -> io::Result<String> { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| pub fn print_and_flush(writer: &mut dyn Write, message: &str) { | ||||||||||||
| use std::io::{Error, ErrorKind}; | ||||||||||||
| fn check_for_writer_error(error: Error) -> Result<(), Error> { | ||||||||||||
| // Do not panic when the process is killed (e.g. piping into `less`). | ||||||||||||
| if matches!(error.kind(), ErrorKind::Interrupted | ErrorKind::BrokenPipe) { | ||||||||||||
| Ok(()) | ||||||||||||
| } else { | ||||||||||||
| Err(error) | ||||||||||||
| use std::io::ErrorKind; | ||||||||||||
|
|
||||||||||||
| const MAX_RETRIES: u32 = 1000; | ||||||||||||
|
||||||||||||
|
|
||||||||||||
| let mut bytes = message.as_bytes(); | ||||||||||||
| let mut retries = 0; | ||||||||||||
| while !bytes.is_empty() { | ||||||||||||
| match writer.write(bytes) { | ||||||||||||
| Ok(0) => break, // EOF | ||||||||||||
|
||||||||||||
| Ok(0) => break, // EOF | |
| Ok(0) => panic!( | |
| "Failed to write: writer returned Ok(0) with {} bytes remaining", | |
| bytes.len() | |
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function lacks documentation explaining its behavior, especially the new WouldBlock handling logic. Consider adding a doc comment that describes what the function does, when it panics, and how it handles different error conditions including WouldBlock, Interrupted, and BrokenPipe.