astral-sh/ruff · error

could not find any tasks matching the given criteria

Error message

could not find any tasks matching the given criteria

What it means

After selecting a source and expanding it to tasks, the evaluator asserts exactly one task matches the given criteria; an empty match set triggers this `anyhow::ensure!` failure. It means the filters (`matches_task`) selected nothing.

Solutions

  1. Verify the file name and cursor index exist in the fixture (count `<CURSOR:...>` directives and files)
  2. Correct the task name/criteria to match the fixture's defined task
  3. Run without restrictive criteria to enumerate the tasks, then pick valid ones

Example fix

# before
ty_completion_eval show-one pandas --file-name complet.py --index 9
// after
ty_completion_eval show-one pandas --file-name completion.py --index 2
Defensive patterns

Strategy: validation

Validate before calling

import re, sys
fixture, fname, idx = sys.argv[1], sys.argv[3], int(sys.argv[5])
text = open(f'crates/ty_python_semantic/resources/mdtest/{fixture}.md').read()
cursors = [m.start() for m in re.finditer(r'<CURSOR:', text)]
if idx >= len(cursors):
    sys.exit(f"fixture has only {len(cursors)} cursors; --index must be smaller")

Try / catch

match show_one(...) {
    Err(e) if e.to_string().contains("could not find any tasks matching") => {
        eprintln!("No task matched; verify --file-name and --index against the fixture");
    }
    result => result,
}

Prevention

When it happens

Trigger: Running `show-one` with criteria (fixture, file name, index, task name) that no generated task satisfies, e.g. a cursor index or file name that doesn't exist in the fixture's expansion.

Common situations: Passing a wrong `--file-name` for the fixture; a cursor `--index` beyond the file's cursors; task names/criteria edited after fixtures changed.

Related errors


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

Appendix: 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 5bb508f594)