BurntSushi/ripgrep · error

{}:{}

Error message

{}:{}

What it means

In patterns_from_path, after the file is opened successfully, patterns_from_reader is called and any error reading or decoding lines is wrapped as format!("{}:{}", path.display(), err) — note the colon (no space) separator, matching the file:line convention. It tells the user the failure originated inside a specific patterns file.

Source

Thrown at crates/cli/src/pattern.rs:91

    })
}

/// Read patterns from a file path, one per line.
///
/// If there was a problem reading or if any of the patterns contain invalid
/// UTF-8, then an error is returned. If there was a problem with a specific
/// pattern, then the error message will include the line number and the file
/// path.
pub fn patterns_from_path<P: AsRef<Path>>(path: P) -> io::Result<Vec<String>> {
    let path = path.as_ref();
    let file = std::fs::File::open(path).map_err(|err| {
        io::Error::new(
            io::ErrorKind::Other,
            format!("{}: {}", path.display(), err),
        )
    })?;
    patterns_from_reader(file).map_err(|err| {
        io::Error::new(
            io::ErrorKind::Other,
            format!("{}:{}", path.display(), err),
        )
    })
}

/// Read patterns from stdin, one per line.
///
/// If there was a problem reading or if any of the patterns contain invalid
/// UTF-8, then an error is returned. If there was a problem with a specific
/// pattern, then the error message will include the line number and the fact
/// that it came from stdin.
pub fn patterns_from_stdin() -> io::Result<Vec<String>> {
    let stdin = io::stdin();
    let locked = stdin.lock();
    patterns_from_reader(locked).map_err(|err| {
        io::Error::new(io::ErrorKind::Other, format!("<stdin>:{}", err))
    })

View on GitHub (pinned to 3fce3b5bb0)

Solutions

  1. Open the patterns file in an editor that highlights invalid UTF-8 and fix or remove the offending line.
  2. Re-save the file as UTF-8 without BOM.
  3. Run iconv or a sanitizer to strip/replace non-UTF-8 bytes before searching.
Defensive patterns

Strategy: try-catch

Validate before calling

fn patterns_file_is_utf8(p: &std::path::Path) -> bool {
    std::fs::read(p).map(|b| std::str::from_utf8(&b).is_ok()).unwrap_or(false)
}

Try / catch

match patterns_from_path(path) {
    Ok(v) => v,
    Err(e) => { eprintln!("{e}"); vec![] }
}

Prevention

When it happens

Trigger: The patterns file opens fine but a line cannot be decoded as UTF-8 (pattern_from_bytes fails inside patterns_from_reader), producing an inner '<line>: <InvalidPatternError>' that gets prefixed with the file path.

Common situations: A patterns file containing one line with invalid UTF-8 bytes; a CRLF/legacy-encoded patterns file; a patterns file corrupted by a bad editor or transfer.

Related errors


AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06). Data as JSON: /data/errors/48de277c419cc25c.json. Report an issue: GitHub.