BurntSushi/ripgrep · error

error reading -f/--file from stdin: stdin has already been c

Error message

error reading -f/--file from stdin: stdin has already been consumed

What it means

Error "error reading -f/--file from stdin: stdin has already been consumed" thrown in BurntSushi/ripgrep.

Source

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

        // 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());
                patterns.push(pat);
            }
        };
        for source in low.patterns.drain(..) {
            match source {
                PatternSource::Regexp(pat) => add(pat),
                PatternSource::File(path) => {
                    if path == Path::new("-") {
                        anyhow::ensure!(
                            !state.stdin_consumed,
                            "error reading -f/--file from stdin: stdin \
                             has already been consumed"
                        );
                        for pat in grep::cli::patterns_from_stdin()? {
                            add(pat);
                        }
                        state.stdin_consumed = true;
                    } else {
                        for pat in grep::cli::patterns_from_path(&path)? {
                            add(pat);
                        }
                    }
                }
            }
        }
        Ok(Patterns { patterns })
    }

View on GitHub (pinned to 3fce3b5bb0)

Solutions

  1. Do not use -f/--file with stdin ('-') when stdin is already being consumed by another option
  2. Read patterns from a real file instead of stdin

When it happens

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