From 0f8873027f82cc06f9ab2b99c0a0b45b69d5ce17 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 5 Dec 2021 01:14:12 -0800 Subject: [PATCH] utils: Don't panic in capture_stream --- src/nix/host/key_uploader.rs | 3 ++- src/util.rs | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/nix/host/key_uploader.rs b/src/nix/host/key_uploader.rs index dc97be5..28539eb 100644 --- a/src/nix/host/key_uploader.rs +++ b/src/nix/host/key_uploader.rs @@ -46,7 +46,8 @@ pub async fn feed_uploader(mut uploader: Child, key: &Key, job: Option PathBuf { } } -pub async fn capture_stream(mut stream: BufReader, job: Option, stderr: bool) -> String { +pub async fn capture_stream(mut stream: BufReader, job: Option, stderr: bool) -> NixResult + where R: AsyncRead + Unpin +{ let mut log = String::new(); loop { let mut line = String::new(); - let len = stream.read_line(&mut line).await.unwrap(); + let len = stream.read_line(&mut line).await?; if len == 0 { break; @@ -188,9 +190,9 @@ pub async fn capture_stream(mut stream: BufReader, job: if let Some(job) = &job { if stderr { - job.stderr(trimmed.to_string()).unwrap(); + job.stderr(trimmed.to_string())?; } else { - job.stdout(trimmed.to_string()).unwrap(); + job.stdout(trimmed.to_string())?; } } @@ -198,7 +200,7 @@ pub async fn capture_stream(mut stream: BufReader, job: log += "\n"; } - log + Ok(log) } pub fn get_label_width(targets: &TargetNodeMap) -> Option {