-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix stream did not contain valid UTF-8 #8120
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -921,13 +921,15 @@ impl PythonRunner { | |
| ) -> Result<PythonRunnerOutput, Error> { | ||
| /// Read lines from a reader and store them in a buffer. | ||
| async fn read_from( | ||
| mut reader: tokio::io::Lines<tokio::io::BufReader<impl tokio::io::AsyncRead + Unpin>>, | ||
| mut reader: tokio::io::Split<tokio::io::BufReader<impl tokio::io::AsyncRead + Unpin>>, | ||
| mut printer: Printer, | ||
| buffer: &mut Vec<String>, | ||
| ) -> io::Result<()> { | ||
| loop { | ||
| match reader.next_line().await? { | ||
| Some(line) => { | ||
| match reader.next_segment().await? { | ||
| Some(line_buf) => { | ||
| let line_buf = line_buf.strip_suffix(b"\r").unwrap_or(&line_buf); | ||
| let line = String::from_utf8_lossy(line_buf).into(); | ||
| let _ = write!(printer, "{line}"); | ||
| buffer.push(line); | ||
| } | ||
|
|
@@ -945,7 +947,7 @@ impl PythonRunner { | |
| .env("PATH", modified_path) | ||
| .env("VIRTUAL_ENV", venv.root()) | ||
| .env("CLICOLOR_FORCE", "1") | ||
| .env("PYTHONIOENCODING", "utf-8") | ||
| .env("PYTHONIOENCODING", "utf-8:backslashreplace") | ||
| .stdout(std::process::Stdio::piped()) | ||
| .stderr(std::process::Stdio::piped()) | ||
| .spawn() | ||
|
|
@@ -956,8 +958,8 @@ impl PythonRunner { | |
| let mut stderr_buf = Vec::with_capacity(1024); | ||
|
|
||
| // Create separate readers for `stdout` and `stderr`. | ||
| let stdout_reader = tokio::io::BufReader::new(child.stdout.take().unwrap()).lines(); | ||
| let stderr_reader = tokio::io::BufReader::new(child.stderr.take().unwrap()).lines(); | ||
| let stdout_reader = tokio::io::BufReader::new(child.stdout.take().unwrap()).split(b'\n'); | ||
| let stderr_reader = tokio::io::BufReader::new(child.stderr.take().unwrap()).split(b'\n'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First thought upon seeing this was thinking, "but what about |
||
|
|
||
| // Asynchronously read from the in-memory pipes. | ||
| let printer = Printer::from(self.level); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I do think
bstrwould be better for this, and would suggest using it (since we already depend on it, albeit transitively, in uv), but my memory here is that we need to write valid UTF-8. So whilebstrwouldn't require this "lossy" step, I believe writing to the underlying stderr would still require valid UTF-8 anyway. Sobstrwould just absolve you of needing to handle line iteration, but I think this is fine as-is.