BurntSushi/ripgrep · error

error: attempted to read patterns from stdin while also sear

Error message

error: attempted to read patterns from stdin while also searching stdin

What it means

Error "error: attempted to read patterns from stdin while also searching stdin" thrown in BurntSushi/ripgrep.

Source

Thrown at crates/core/flags/hiargs.rs:1121

}

impl Paths {
    /// Drain the search paths out of the given low arguments.
    fn from_low_args(
        state: &mut State,
        _: &Patterns,
        low: &mut LowArgs,
    ) -> anyhow::Result<Paths> {
        // We require a `&Patterns` even though we don't use it to ensure that
        // patterns have already been read from LowArgs. This let's us safely
        // assume that all remaining positional arguments are intended to be
        // file paths.

        let mut paths = Vec::with_capacity(low.positional.len());
        for osarg in low.positional.drain(..) {
            let path = PathBuf::from(osarg);
            if state.stdin_consumed && path == Path::new("-") {
                anyhow::bail!(
                    "error: attempted to read patterns from stdin \
                     while also searching stdin",
                );
            }
            paths.push(path);
        }
        log::debug!("number of paths given to search: {}", paths.len());
        if !paths.is_empty() {
            let is_one_file = paths.len() == 1
                // Note that we specifically use `!paths[0].is_dir()` here
                // instead of `paths[0].is_file()`. Namely, the latter can
                // return `false` even when the path is something resembling
                // a file. So instead, we just consider the path a file as
                // long as we know it isn't a directory.
                //
                // See: https://github.com/BurntSushi/ripgrep/issues/2736
                && (paths[0] == Path::new("-") || !paths[0].is_dir());
            log::debug!("is_one_file? {is_one_file:?}");

View on GitHub (pinned to 3fce3b5bb0)

Solutions

  1. Either read patterns from stdin (-f -) or search stdin, not both
  2. Redirect patterns from a file and let stdin be searched, or vice versa

When it happens

Trigger: Thrown at crates/core/flags/hiargs.rs:1121 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/d8e3674311532590.json. Report an issue: GitHub.