BurntSushi/ripgrep · error
pattern given is not valid UTF-8
Error message
pattern given is not valid UTF-8
What it means
Error "pattern given is not valid UTF-8" thrown in BurntSushi/ripgrep.
Source
Thrown at crates/core/flags/hiargs.rs:1039
// search and neither -e/--regexp nor -f/--file is given. Basically,
// the first positional is a pattern only when a pattern hasn't been
// given in some other way.
// No search means no patterns. Even if -e/--regexp or -f/--file is
// given, we know we won't use them so don't bother collecting them.
if !matches!(low.mode, Mode::Search(_)) {
return Ok(Patterns { patterns: vec![] });
}
// If we got nothing from -e/--regexp and -f/--file, then the first
// positional is a pattern.
if low.patterns.is_empty() {
anyhow::ensure!(
!low.positional.is_empty(),
"ripgrep requires at least one pattern to execute a search"
);
let ospat = low.positional.remove(0);
let Ok(pat) = ospat.into_string() else {
anyhow::bail!("pattern given is not valid UTF-8")
};
return Ok(Patterns { patterns: vec![pat] });
}
// Otherwise, we need to slurp up our patterns from -e/--regexp and
// -f/--file. We de-duplicate as we go. If we don't de-duplicate,
// then it can actually lead to major slow downs for sloppy inputs.
// This might be surprising, and the regex engine will eventually
// de-duplicate duplicative branches in a single regex (maybe), but
// not until after it has gone through parsing and some other layers.
// If there are a lot of duplicates, then that can lead to a sizeable
// extra cost. It is lamentable that we pay the extra cost here to
// de-duplicate for a likely uncommon case, but I've seen this have a
// big impact on real world data.
let mut seen = HashSet::new();
let mut patterns = Vec::with_capacity(low.patterns.len());
let mut add = |pat: String| {
if !seen.contains(&pat) {
seen.insert(pat.clone());View on GitHub (pinned to 3fce3b5bb0)
Solutions
- Ensure the pattern is valid UTF-8
- Use escape sequences or --encoding to supply non-UTF-8 patterns
When it happens
Trigger: Thrown at crates/core/flags/hiargs.rs:1039 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06).
Data as JSON: /data/errors/493dfd78d2f7769c.json.
Report an issue: GitHub.