diff options
author | Andrew Gallant <jamslam@gmail.com> | 2024-01-06 14:15:52 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2024-01-06 14:15:52 -0500 |
commit | c8e4a84519ede79b330f9a9e2b072110d5bd0c8c (patch) | |
tree | 5af886c28d10672f2d6704a79de956f40aded894 | |
parent | f02a50a69da131269fe0d8460e08b1fceea04ca9 (diff) |
cli: prefix all non-fatal error messages with 'rg: '
Fixes #2694
-rw-r--r-- | crates/core/messages.rs | 14 | ||||
-rw-r--r-- | tests/feature.rs | 2 | ||||
-rw-r--r-- | tests/regression.rs | 2 |
3 files changed, 13 insertions, 5 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); } }} } diff --git a/tests/feature.rs b/tests/feature.rs index 5a2cff4f..680bacda 100644 --- a/tests/feature.rs +++ b/tests/feature.rs @@ -975,7 +975,7 @@ rgtest!(f1404_nothing_searched_warning, |dir: Dir, mut cmd: TestCommand| { let output = cmd.raw_output(); let stderr = String::from_utf8_lossy(&output.stderr); let expected = "\ - No files were searched, which means ripgrep probably applied \ + rg: No files were searched, which means ripgrep probably applied \ a filter you didn't expect.\n\ Running with --debug will show why files are being skipped.\n\ "; diff --git a/tests/regression.rs b/tests/regression.rs index ef0a3339..e28af4a3 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -402,7 +402,7 @@ rgtest!(r428_unrecognized_style, |dir: Dir, mut cmd: TestCommand| { let output = cmd.raw_output(); let stderr = String::from_utf8_lossy(&output.stderr); let expected = "\ -error parsing flag --colors: \ +rg: error parsing flag --colors: \ unrecognized style attribute ''. Choose from: nobold, bold, nointense, \ intense, nounderline, underline. "; |