Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use different exit codes for "no match" and "error" #948

Closed
Delodax opened this issue Jun 15, 2018 · 3 comments
Closed

use different exit codes for "no match" and "error" #948

Delodax opened this issue Jun 15, 2018 · 3 comments
Labels
enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue.

Comments

@Delodax
Copy link

Delodax commented Jun 15, 2018

What version of ripgrep are you using?

0.8.1

How did you install ripgrep?

Homebrew

What operating system are you using ripgrep on?

macOS 10.13.5

Describe your question, feature request, or bug.

Hi!

I am using ripgrep from within a node.js program using child_process.exec(). I've noticed that when I don't find anyhting in a search, ripgrep terminates with a non-zero exit code thus informing child_process.exec() that "something went wrong".

I'd simply like to know, if there is any flag one can use or other measure to prevent a non-zero exit code during the aforementioned circumstances. I can solve the issue from with the node.js program, but would think "manipulating" the exit code would be a more elegant solution.

@BurntSushi
Copy link
Owner

I've noticed that when I don't find anyhting in a search, ripgrep terminates with a non-zero exit code

This is intended behavior. ripgrep continues this very long held tradition from grep, and I don't see myself changing it or providing a flag to change it.

One place where ripgrep could probably use some improvement is in refining its exit codes. Namely, I think ripgrep only ever produces 0 or 1 as an exit code, but it would be nice to reserve 1 for "no match" and use some other exit code (probably 2) in the case of a real error. This is what GNU grep does.

@BurntSushi BurntSushi changed the title Exit code musing use different exit codes for "no match" and "error" Jun 15, 2018
@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label Jun 15, 2018
@Delodax
Copy link
Author

Delodax commented Jun 15, 2018

Thanks for the quick feedback. Your solution wrt extending the breadth of exit codes sounds great. 👍

@BurntSushi
Copy link
Owner

BurntSushi commented Jun 15, 2018

Interestingly, it looks like this might be border-line trivial to fix. This is ripgrep's current main function:

ripgrep/src/main.rs

Lines 56 to 66 in 15fa77c

fn main() {
reset_sigpipe();
match Args::parse().map(Arc::new).and_then(run) {
Ok(0) => process::exit(1),
Ok(_) => process::exit(0),
Err(err) => {
eprintln!("{}", err);
process::exit(1);
}
}
}

I think all that needs to happen is to change the error case to process::exit(2).

There is still the matter of writing a test and updating/adding relevant docs, which might be a bit more work since I can't remember if the test harness tries to control the exit status, but either way, shouldn't be too bad.

I can patch this myself when I get a chance, but this does seem like an easy task that anyone could take on if they wanted to!

@BurntSushi BurntSushi added the help wanted Others are encouraged to work on this issue. label Jun 15, 2018
BurntSushi pushed a commit that referenced this issue Jun 19, 2018
Exit code 1 was shared to indicate both "no results" and "error." Use
status code 2 to indicate errors, similar to grep's behavior.

Fixes #948 

PR #954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue.
Projects
None yet
Development

No branches or pull requests

2 participants