Skip to content

Commit

Permalink
search: better errors for preprocessor commands
Browse files Browse the repository at this point in the history
If a preprocessor command could not be started, we now show some
additional context with the error message. Previously, it showed
something like this:

  some/file: No such file or directory (os error 2)

Which is itself pretty misleading. Now it shows:

  some/file: preprocessor command could not start: '"nonexist" "some/file"': No such file or directory (os error 2)

Fixes #1302
  • Loading branch information
BurntSushi committed Jun 16, 2019
1 parent 50bcb74 commit d1389db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bug fixes:

* [BUG #1259](https://github.com/BurntSushi/ripgrep/issues/1259):
Fix bug where the last byte of a `-f file` was stripped if it wasn't a `\n`.
* [BUG #1302](https://github.com/BurntSushi/ripgrep/issues/1302):
Show better error messages when a non-existent preprocessor command is given.


11.0.1 (2019-04-16)
Expand Down
14 changes: 13 additions & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,19 @@ impl<W: WriteColor> SearchWorker<W> {
let mut cmd = Command::new(&bin);
cmd.arg(path).stdin(Stdio::from(File::open(path)?));

let rdr = self.command_builder.build(&mut cmd)?;
let rdr = self
.command_builder
.build(&mut cmd)
.map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!(
"preprocessor command could not start: '{:?}': {}",
cmd,
err,
),
)
})?;
self.search_reader(path, rdr).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
Expand Down

0 comments on commit d1389db

Please sign in to comment.