{"record":{"id":"f719c6ee4b2b0a03","repo":"astral-sh/ruff","slug":"expected-at-least-one-path-to-search-for-python-fi","errorCode":null,"errorMessage":"Expected at least one path to search for Python files","messagePattern":"Expected at least one path to search for Python files","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_workspace/src/resolver.rs","lineNumber":529,"sourceCode":"                } else {\n                    // We already visited this ancestor, we can stop here.\n                    break;\n                }\n            }\n        }\n    }\n\n    // Check if the paths themselves are excluded.\n    if resolver.force_exclude() {\n        paths.retain(|path| !is_file_excluded(path, &resolver));\n        if paths.is_empty() {\n            return Ok((vec![], resolver));\n        }\n    }\n\n    let (first_path, rest_paths) = paths\n        .split_first()\n        .ok_or_else(|| anyhow!(\"Expected at least one path to search for Python files\"))?;\n    // Create the `WalkBuilder`.\n    let mut builder = WalkBuilder::new(first_path);\n\n    if let Ok(cwd) = std::env::current_dir() {\n        builder.current_dir(cwd);\n    }\n\n    for path in rest_paths {\n        builder.add(path);\n    }\n    builder.standard_filters(resolver.respect_gitignore());\n    builder.hidden(false);\n\n    builder.threads(\n        std::thread::available_parallelism()\n            .map_or(1, std::num::NonZeroUsize::get)\n            .min(12),\n    );","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_workspace/src/resolver.rs#L511-L547","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass at least one path argument (e.g. the current directory `.`) to the check/format command","Fix the calling code so it never invokes `project_files_in_path` with an empty slice; default to `[cwd]` when no paths are given"],"exampleFix":"// before\nresolver::project_files_in_path(&settings, &[], ...)?\n// after\nlet paths = if paths.is_empty() { vec![std::env::current_dir()? ] } else { paths };\nresolver::project_files_in_path(&settings, &paths, ...)?","handlingStrategy":"validation","validationCode":"if paths.is_empty() {\n    anyhow::bail!(\"Expected at least one path to search for Python files\");\n}\nresolver::project_files_in_path(&settings, &paths, ...)?;","typeGuard":null,"tryCatchPattern":"match resolver::project_files_in_path(&settings, &paths, ...) {\n    Ok((paths, resolver)) => { /* ... */ }\n    Err(e) if e.to_string().contains(\"at least one path\") => eprintln!(\"Usage: provide at least one path\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Always default the paths argument to [cwd] or [\".\"] when no user paths are supplied","Add a clap `num_args(1..)` / required positional check so the CLI rejects empty path lists early","Unit-test library entry points with empty input to confirm the guard fires before walking"],"tags":["cli","path-resolution","argument-validation"],"backgroundTag":"empty-required-argument","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}