astral-sh/ruff · error

Expected at least one path to search for Python files

Error message

Expected at least one path to search for Python files

What it means

Ruff's resolver requires at least one filesystem path to walk for Python files. `project_files_in_path` splits its `paths` argument with `split_first()` and throws this anyhow error when the slice is empty, because the `WalkBuilder` needs a first path to seed the directory walk.

Solutions

  1. Pass at least one path argument (e.g. the current directory `.`) to the check/format command
  2. Fix the calling code so it never invokes `project_files_in_path` with an empty slice; default to `[cwd]` when no paths are given

Example fix

// before
resolver::project_files_in_path(&settings, &[], ...)?
// after
let paths = if paths.is_empty() { vec![std::env::current_dir()? ] } else { paths };
resolver::project_files_in_path(&settings, &paths, ...)?
Defensive patterns

Strategy: validation

Validate before calling

if paths.is_empty() {
    anyhow::bail!("Expected at least one path to search for Python files");
}
resolver::project_files_in_path(&settings, &paths, ...)?;

Try / catch

match resolver::project_files_in_path(&settings, &paths, ...) {
    Ok((paths, resolver)) => { /* ... */ }
    Err(e) if e.to_string().contains("at least one path") => eprintln!("Usage: provide at least one path"),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `project_files_in_path` (directly or via `ruff check`, `ruff format`, `add_noqa`, `analyze graph`, `show-files`, `show-settings`) with an empty `paths` vector, e.g. after argument handling yields no paths.

Common situations: Invoking the library API programmatically without passing a path; wiring that filters file arguments to zero; tool wrappers that strip all positional arguments before calling ruff's internals.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/f719c6ee4b2b0a03. Report an issue: GitHub.

Appendix: source

Thrown at crates/ruff_workspace/src/resolver.rs:529

                } else {
                    // We already visited this ancestor, we can stop here.
                    break;
                }
            }
        }
    }

    // Check if the paths themselves are excluded.
    if resolver.force_exclude() {
        paths.retain(|path| !is_file_excluded(path, &resolver));
        if paths.is_empty() {
            return Ok((vec![], resolver));
        }
    }

    let (first_path, rest_paths) = paths
        .split_first()
        .ok_or_else(|| anyhow!("Expected at least one path to search for Python files"))?;
    // Create the `WalkBuilder`.
    let mut builder = WalkBuilder::new(first_path);

    if let Ok(cwd) = std::env::current_dir() {
        builder.current_dir(cwd);
    }

    for path in rest_paths {
        builder.add(path);
    }
    builder.standard_filters(resolver.respect_gitignore());
    builder.hidden(false);

    builder.threads(
        std::thread::available_parallelism()
            .map_or(1, std::num::NonZeroUsize::get)
            .min(12),
    );

View on GitHub (pinned to 26f38c119c)