BurntSushi/ripgrep · error
<stdin>:{}
Error message
<stdin>:{} What it means
In patterns_from_stdin, any error from patterns_from_reader (a line that is not valid UTF-8) is wrapped as format!("<stdin>:{}", err). The '<stdin>' label identifies the source as standard input rather than a file path, preserving the file:line convention used elsewhere.
Source
Thrown at crates/cli/src/pattern.rs:108
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))
})
}
/// Read patterns from any reader, 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.
///
/// Note that this routine uses its own internal buffer, so the caller should
/// not provide their own buffered reader if possible.
///
/// # Example
///
/// This shows how to parse patterns, one per line.
///
/// ```
/// use grep_cli::patterns_from_reader;View on GitHub (pinned to 3fce3b5bb0)
Solutions
- Ensure the data piped to stdin is valid UTF-8, one pattern per line.
- Filter the stream through iconv -f latin1 -t utf-8 or tr to strip non-UTF-8 bytes before it reaches the tool.
- Pass patterns via a file or --regex argument instead of stdin if the source is inherently binary.
Defensive patterns
Strategy: try-catch
Try / catch
match patterns_from_stdin() {
Ok(v) => v,
Err(e) => { eprintln!("{e}"); vec![] }
} Prevention
- Pipe only valid UTF-8 to pattern-reading stdin modes.
- Filter stdin through iconv/tr when the source may be non-UTF-8.
- Prefer a patterns file or --regex argument for inherently binary sources.
When it happens
Trigger: Piping binary or non-UTF-8 data into a tool that reads patterns via patterns_from_stdin (e.g. rg -f - with a pattern list on stdin), where one input line fails pattern_from_bytes UTF-8 validation.
Common situations: cat binaryfile | rg -f -; a shell heredoc feeding patterns that contains a stray high byte; cross-platform line-ending issues from a redirected file.
Related errors
- found invalid UTF-8 in pattern at byte offset {}: {} (disabl
- {}:{}
- {}: {}
- invalid format for size '{}', which should be a non-empty se
- invalid integer found in size '{}': {}
AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06).
Data as JSON: /data/errors/d434489fdf9964eb.json.
Report an issue: GitHub.