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

args: Do not attempt to build glob options when not specified. #1400

Closed
wants to merge 1 commit into from

Conversation

JesseH-
Copy link

@JesseH- JesseH- commented Oct 8, 2019

Closes #1291

This is a first shot at addressing #1291, though I think some additional input is needed.

After reviewing and manually testing, I found that the source of the errors being raised was due to unconditionally building an OverrideBuilder from the globbing options. As this relies on the current working directory, it understandably fails when the cwd does not exist.

The immediate error can be suppressed by checking that the globbing options are actually required before attempting to handle them. This will still raise the same error when any of these options are present without an existing cwd, though perhaps a clearer error message could also be emitted as part of this change in that case.

On the testing front, I wasn't able to suitably recreate the original issue in a regression test. In my experiments, I tried to set the current_dir of the TestCommand to something non-existent before running, but this seemed to result in a panic before actually entering any ripgrep code when we go to execute the command.

Manual testing showed that we were able to execute non-globbing ripgrep commands without failure from a non-existent cwd with this change applied.

BurntSushi added a commit that referenced this pull request Feb 17, 2020
It turns out that querying the CWD while in a directory that no longer
exists results in an error. Since the CWD is queried every time ripgrep
starts---whether it needs it or not---for dealing with glob matching,
ripgrep winds up being completely useless inside a non-existent
directory.

We fix this in a few different ways:

* Firstly, if std::env::current_dir() fails, then we fall back to trying
  to read the `PWD` environment variable.
* If that fails, that we return a more sensible error message so that a
  user can at least react to the problem. Previously, the error message
  was inscrutable.
* Finally, we try to avoid the problem altogether by building empty glob
  matchers if not globs were provided, thus side-stepping querying the
  CWD completely.

Fixes #1291, Closes #1400
@BurntSushi BurntSushi added the rollup A PR that has been merged with many others in a rollup. label Feb 17, 2020
@BurntSushi
Copy link
Owner

Thank you very much for this PR! I ended up going in a different direction. In particular:

  • I created a new current_dir helper function. If std::env::curent_dir fails, then ripgrep will try to read PWD. If that fails, then ripgrep will print a more reasonable error message.
  • Similarish to what you did, if ripgrep does not need to build the glob matchers, then it just creates an empty Override matcher.

While I didn't end up using your PR, your diagnosis of the situation was super helpful. Likely saved me quite a bit of time! So thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR that has been merged with many others in a rollup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doesn't work in a nonexistent dir
2 participants