ripgrep icon indicating copy to clipboard operation
ripgrep copied to clipboard

improve error messages when -f flag fails

Open BurntSushi opened this issue 8 years ago • 8 comments

For example:

$ rg -e foo -f src/search_stream.rs 
Error parsing regex near 'fer.|*/|z{' at character offset 213: Invalid application of repetition operator to: '(?u:f)(?u:o)(?u:o)|(?u:/)*(?u:!)|(?u:T)(?u:h)(?u:e)

Aside from the badly formatted regex error message (see #395), the error message should show the file path and probably also the line number at which the error occurred.

BurntSushi avatar May 09 '17 17:05 BurntSushi

let me see what I can do.

nateozem avatar May 17 '17 10:05 nateozem

@BurntSushi I submitted a PR to address this issue. It also tries to avoid the problem with the AST dump (issue https://github.com/BurntSushi/ripgrep/issues/395).

I have one question. Were you thinking about reporting the file path and line number where the error occurred in regex?

andrea-prearo avatar Aug 30 '17 20:08 andrea-prearo

I have one question. Were you thinking about reporting the file path and line number where the error occurred in regex?

Probably not. I could maybe see a case for pushing the line number reporting into the regex crate, but certainly not the file path.

BurntSushi avatar Aug 30 '17 20:08 BurntSushi

Got it. Thanks!

andrea-prearo avatar Aug 30 '17 21:08 andrea-prearo

looks like you can close this issue due to rust-lang/regex#396

I am lurking around the repo as a happy user of ripgrep - thanks for the awesome project

petr-tik avatar Feb 04 '19 15:02 petr-tik

@petr-tik Thanks for the kind words, but this is definitely not fixed yet. For example:

$ cat /tmp/patterns
foo
bar(wat
quux

$ rg -f /tmp/patterns
regex parse error:
    foo|bar(wat|quux
           ^
error: unclosed group

There are a few problems here:

  1. The file path of the pattern file isn't shown in the error message. This is important if you use -f multiple times.
  2. There is no line number corresponding to the pattern that failed to parse.
  3. The error shows all of the patterns in the file given joined with a | instead of just the pattern that is invalid.

BurntSushi avatar Feb 04 '19 16:02 BurntSushi

I must have misunderstood the PRs. Only wanted to help you declutter your issues, in case it had been forgotten.

petr-tik avatar Feb 04 '19 16:02 petr-tik

Which files in the repo could be relevant to this?

J-Kappes avatar Sep 05 '23 12:09 J-Kappes