BurntSushi/ripgrep · error
{}: {}
Error message
{}: {} What it means
In patterns_from_path, the call to std::fs::File::open(path) is wrapped so the IO error is prefixed with the file path: format!("{}: {}", path.display(), err). This is a user-facing message format, not a distinct error type — it annotates *which* patterns file could not be opened and why.
Source
Thrown at crates/cli/src/pattern.rs:85
pub fn pattern_from_bytes(
pattern: &[u8],
) -> Result<&str, InvalidPatternError> {
std::str::from_utf8(pattern).map_err(|err| InvalidPatternError {
original: escape(pattern),
valid_up_to: err.valid_up_to(),
})
}
/// 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.View on GitHub (pinned to 3fce3b5bb0)
Solutions
- Verify the path exists and is a readable regular file before passing it.
- Fix typos or relative-path issues (run from the expected working directory, or use an absolute path).
- Correct file permissions (chmod +r) so the process can open it.
Example fix
// before
let pats = patterns_from_path("missing.txt")?;
// after
let path = "patterns.txt";
assert!(std::fs::metadata(path).is_ok(), "patterns file missing");
let pats = patterns_from_path(path)?; Defensive patterns
Strategy: validation
Validate before calling
fn readable_patterns_file(p: &std::path::Path) -> bool {
std::fs::metadata(p).map(|m| m.is_file()).unwrap_or(false)
} Try / catch
let pats = patterns_from_path(path);
if let Err(e) = pats { eprintln!("{e}"); return; } Prevention
- Check the path exists and is readable before calling patterns_from_path.
- Use absolute paths or assert the working directory in CLI tools.
- Surface the file path in errors so users can locate the missing file.
When it happens
Trigger: Calling patterns_from_path with a path that does not exist, is unreadable (permissions), or names a directory rather than a file, causing File::open to fail.
Common situations: rg -f missingfile; --patterns-file pointing at a typo'd path; running in a directory where the patterns file is chmod 000; CI checking out a repo without the referenced patterns file.
Related errors
- found invalid UTF-8 in pattern at byte offset {}: {} (disabl
- {}:{}
- <stdin>:{}
- preprocessor command failed: '{cmd:?}': {err}
- invalid format for size '{}', which should be a non-empty se
AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06).
Data as JSON: /data/errors/b9ffb5d41a84a797.json.
Report an issue: GitHub.