FuelLabs/fuels-rs · error
failed grep command
Error message
failed grep command
What it means
check-docs shells out to the grep binary via std::process::Command and expects the spawn itself to succeed. The expect fires when grep cannot be spawned at all, most commonly because grep is not installed or not on PATH. A grep that runs but exits non-zero is a different, separately handled error (bail!).
Source
Thrown at scripts/check-docs/src/lib.rs:240
.expect("could not canonicalize md path");
(!md_files_summary.contains(&file))
.then(|| anyhow!("file `{}` not in SUMMARY.md", file.to_str().unwrap()))
})
.collect()
}
pub fn search_for_pattern(pattern: &str, location: &str) -> anyhow::Result<String> {
let grep_project = std::process::Command::new("grep")
.arg("-H") // print filename
.arg("-n") // print line-number
.arg("-r") // search recursively
.arg("--binary-files=without-match")
.arg("--exclude-dir=check-docs")
.arg(pattern)
.arg(location)
.output()
.expect("failed grep command");
if !grep_project.status.success() {
bail!("Failed running `grep` command for pattern '{}'", pattern);
}
Ok(String::from_utf8(grep_project.stdout)?)
}
pub fn find_files(pattern: &str, location: &str, exclude: &str) -> anyhow::Result<String> {
let find = std::process::Command::new("find")
.args([
location, "-type", "f", "-name", pattern, "!", "-name", exclude,
])
.output()
.expect("Program `find` not in PATH");
if !find.status.success() {
bail!("Failed running `find` command for pattern {}", pattern);View on GitHub (pinned to d9a250a518)
Solutions
- Install grep in the execution image (apt-get install -y grep / apk add grep)
- Run the script in the CI image that already ships core utilities
- Fix PATH if grep exists on disk but is not found
Example fix
# before: minimal image without coreutils RUN cargo run -p scripts/check-docs # after: install grep first RUN apt-get update && apt-get install -y grep cargo run -p scripts/check-docs
Defensive patterns
Strategy: fallback
Validate before calling
# (shell) availability check before running check-docs
command -v grep >/dev/null || { echo 'grep is required by check-docs'; exit 1; } Prevention
- Install grep in the CI image running docs checks
- Or replace the external grep call with an in-Rust search (walkdir + regex) to remove the system dependency
- Document the tool's system requirements in the script README
When it happens
Trigger: Running check-docs in a minimal container image (distroless, scratch-based) without grep installed, or with a PATH scrubbed by the CI environment so Command::new("grep") cannot resolve the binary.
Common situations: Lean CI images lacking core utilities; PATH misconfiguration; cross-environment script runs.
Related errors
- Program `find` not in PATH
- could not canonicalize md path
- No anchor available to satisfy include {include:?}
- Anchor unused: {unused_anchor:?}!
- {the_path:?} when canonicalized gives error {err:?}\ninclude
AI-assisted analysis of FuelLabs/fuels-rs@d9a250a518 (2026-08-16).
Data as JSON: /api/errors/d53c5b6b711129d8.
Report an issue: GitHub.