If writing an error to the pager fails, write it to stderr

Josh Triplett created

This ensures that errors about the pager itself, such as broken pipes,
show up somewhere.

Change summary

src/main.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Detailed changes

src/main.rs 🔗

@@ -624,7 +624,9 @@ impl Output {
 
     fn write_err(&mut self, msg: &str) {
         if self.include_stderr {
-            write!(self, "{}", msg).unwrap();
+            if write!(self, "{}", msg).is_err() {
+                write!(std::io::stderr(), "{}", msg).unwrap();
+            }
         } else {
             write!(std::io::stderr(), "{}", msg).unwrap();
         }