-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): persist logs on failure (#7805)
### Description If a task fails when using the UI, it isn't easy to find the reason for the failure. This PR makes it so that if a task fails, we'll persist the logs to the terminal so they remain after the UI exits. ### Testing Instructions <img width="1034" alt="Screenshot 2024-03-21 at 9 46 11 AM" src="https://github.com/vercel/turbo/assets/4131117/31a6f29d-22c2-4ad9-a569-a95afb200f54"> Closes TURBO-2681
- Loading branch information
1 parent
1644246
commit 893dfd5
Showing
6 changed files
with
92 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::io::Write; | ||
|
||
/// Writer that will buffer writes so the underlying writer is only called with | ||
/// writes that end in a newline | ||
pub struct LineWriter<W> { | ||
writer: W, | ||
buffer: Vec<u8>, | ||
} | ||
|
||
impl<W: Write> LineWriter<W> { | ||
pub fn new(writer: W) -> Self { | ||
Self { | ||
writer, | ||
buffer: Vec::with_capacity(512), | ||
} | ||
} | ||
} | ||
|
||
impl<W: Write> Write for LineWriter<W> { | ||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { | ||
for line in buf.split_inclusive(|c| *c == b'\n') { | ||
if line.ends_with(b"\n") { | ||
if self.buffer.is_empty() { | ||
self.writer.write_all(line)?; | ||
} else { | ||
self.buffer.extend_from_slice(line); | ||
self.writer.write_all(&self.buffer)?; | ||
self.buffer.clear(); | ||
} | ||
} else { | ||
// This should only happen on the last chunk? | ||
self.buffer.extend_from_slice(line) | ||
} | ||
} | ||
|
||
Ok(buf.len()) | ||
} | ||
|
||
fn flush(&mut self) -> std::io::Result<()> { | ||
// We don't flush our buffer as that would lead to a write without a newline | ||
self.writer.flush() | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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