astral-sh/ruff · error · anyhow::Error

found more than one task matching the given criteria

Error message

found more than one task matching the given criteria

What it means

The inverse of the empty-match guard: `show-one` must resolve to exactly one task, so filters matching two or more `<CURSOR>` directives abort here. Because an omitted filter matches every task, specifying only the fixture (or only a file with multiple directives) is ambiguous by design — add `--file-name` and `--index` until exactly one task remains.

Source

Thrown at crates/ty_completion_eval/src/main.rs:183

    let sources = TaskSource::all(&truth)?;
    match args.command {
        Command::ShowOne(ref cmd) => {
            tmp_eval_dir.disable_cleanup(cmd.keep_tmp_dir);

            let Some(source) = sources
                .iter()
                .find(|source| cmd.matches_source_task(source))
            else {
                anyhow::bail!("could not find task named `{}`", cmd.task_name);
            };
            let tasks = source.to_tasks(&tmp_eval_path)?;
            let matching: Vec<&Task> = tasks.iter().filter(|task| cmd.matches_task(task)).collect();
            anyhow::ensure!(
                !matching.is_empty(),
                "could not find any tasks matching the given criteria",
            );
            anyhow::ensure!(
                matching.len() < 2,
                "found more than one task matching the given criteria",
            );
            let task = &matching[0];
            let completions = task.completions()?;

            let mut stdout = std::io::stdout().lock();
            for (i, c) in completions.iter().enumerate() {
                write!(stdout, "{}", c.name.as_str())?;
                if let Some(module_name) = c.module_name {
                    write!(stdout, " (module: {module_name})")?;
                }
                if task.cursor.answer.matches(c) {
                    write!(stdout, " (*, {}/{})", i + 1, completions.len())?;
                }
                writeln!(stdout)?;
            }
            writeln!(stdout, "-----")?;

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Add `--file-name` if you only specified the fixture name
  2. Add `--index` (zero-based, per the CSV) if the file still matches multiple cursors
  3. Consult the CSV rows for that fixture to choose a unique (file, index) pair

Example fix

# before (file has multiple cursors; ambiguous)
cargo run -p ty_completion_eval -- show-one custom-types --file-name main.py
# after
cargo run -p ty_completion_eval -- show-one custom-types --file-name main.py --index 0
Defensive patterns

Strategy: validation

Validate before calling

n=$(grep -c '<CURSOR' "$FIXTURE_FILE")
[ "$n" -le 1 ] || echo "this file has $n cursors; pass --index too" >&2

Prevention

When it happens

Trigger: Omitting both `--file-name` and `--index` in a fixture with more than one cursor directive; specifying only `--file-name` when that file contains multiple `<CURSOR>` markers.

Common situations: Quick inspection runs where the developer expects `show-one` to default to the first task; fixtures grown over time so a previously-unique file filter now matches several cursors.

Related errors


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/344935a89f27963a. Report an issue: GitHub.