Skip to content

core: report pattern file source in regex errors#3463

Open
bugprone wants to merge 2 commits into
BurntSushi:masterfrom
bugprone:fix-pattern-file-regex-errors
Open

core: report pattern file source in regex errors#3463
bugprone wants to merge 2 commits into
BurntSushi:masterfrom
bugprone:fix-pattern-file-regex-errors

Conversation

@bugprone

@bugprone bugprone commented Jul 6, 2026

Copy link
Copy Markdown

Fixes #478.

Summary

When a regex parse error comes from a pattern loaded via -f, ripgrep now prefixes the original regex error with the pattern source path and line number.

The normal path still uses the existing build_many matcher construction. On compile failure, ripgrep checks individual patterns only to identify whether the failing pattern came from -f.

Example

Given two pattern files:

# patterns1
foo
# patterns2
bar
bar(wat
quux

Running:

$ rg -f patterns1 -f patterns2 haystack

Previously reported the error against the alternation built from all patterns:

rg: regex parse error:
    (?:foo)|(?:bar)|(?:bar(wat)|(?:quux)
                    ^
error: unclosed group

Now the error points back to the pattern file and line:

rg: patterns2:2: regex parse error:
    (?:bar(wat)
    ^
error: unclosed group

PCRE2 keeps its own error text with the same patterns2:2: source prefix.

Notes

Tests

$ cargo fmt --all -- --check
$ git diff --check origin/master..HEAD
$ cargo test -p ripgrep --test integration
$ cargo test -p ripgrep --test integration --features pcre2
$ cargo test --workspace --features pcre2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve error messages when -f flag fails

1 participant