summaryrefslogtreecommitdiffstats
path: root/crates/core/messages.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/core/messages.rs')
-rw-r--r--crates/core/messages.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/core/messages.rs b/crates/core/messages.rs
index ea514c17..2f723509 100644
--- a/crates/core/messages.rs
+++ b/crates/core/messages.rs
@@ -39,21 +39,29 @@ macro_rules! eprintln_locked {
// lock stdout before printing to stderr. This avoids interleaving
// lines within ripgrep because `search_parallel` uses `termcolor`,
// which accesses the same stdout lock when writing lines.
- let stdout = std::io::stdout();
- let _handle = stdout.lock();
+ let stdout = std::io::stdout().lock();
+ let mut stderr = std::io::stderr().lock();
// We specifically ignore any errors here. One plausible error we
// can get in some cases is a broken pipe error. And when that
// occurs, we should exit gracefully. Otherwise, just abort with
// an error code because there isn't much else we can do.
//
// See: https://github.com/BurntSushi/ripgrep/issues/1966
- if let Err(err) = writeln!(std::io::stderr(), $($tt)*) {
+ if let Err(err) = write!(stderr, "rg: ") {
if err.kind() == std::io::ErrorKind::BrokenPipe {
std::process::exit(0);
} else {
std::process::exit(2);
}
}
+ if let Err(err) = writeln!(stderr, $($tt)*) {
+ if err.kind() == std::io::ErrorKind::BrokenPipe {
+ std::process::exit(0);
+ } else {
+ std::process::exit(2);
+ }
+ }
+ drop(stdout);
}
}}
}