diff --git a/rust/rhg/src/ui.rs b/rust/rhg/src/ui.rs --- a/rust/rhg/src/ui.rs +++ b/rust/rhg/src/ui.rs @@ -49,7 +49,7 @@ .write_all(bytes) .or_else(|e| handle_stderr_error(e))?; - stderr.flush().or_else(|e| Err(UiError::StderrError(e))) + stderr.flush().or_else(|e| handle_stderr_error(e)) } } @@ -94,3 +94,13 @@ Err(UiError::StdoutError(error)) } + +/// Sometimes writing to stderr is not possible. +fn handle_stderr_error(error: io::Error) -> Result<(), UiError> { + // A broken pipe should not result in a error + // like with `| head` for example + if let ErrorKind::BrokenPipe = error.kind() { + return Ok(()); + } + Err(UiError::StdoutError(error)) +}