changeset 45367:53af26aa5951

rhg: handle broken pipe error for stderr Differential Revision: https://phab.mercurial-scm.org/D8871
author Antoine Cezar <antoine.cezar@octobus.net>
date Fri, 24 Jul 2020 10:34:04 +0200
parents 10c36ead86f8
children d71693f799a0
files rust/rhg/src/ui.rs
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/ui.rs	Fri Jul 24 17:24:10 2020 +0200
+++ b/rust/rhg/src/ui.rs	Fri Jul 24 10:34:04 2020 +0200
@@ -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))
+}