denoland/deno · error

Bench failed because the "only" option was used

Error message

Bench failed because the "only" option was used

What it means

deno bench deliberately fails the entire run with this error when any benchmark was registered with the 'only' option (Bench.only(...) or { only: true }), exactly like test runners treat .only. The benchmarks still execute and are reported (reporter.report_end runs first), but the process exits non-zero so a forgotten 'only' can never silently shrink CI coverage (cli/tools/bench/mod.rs:367-415).

Source

Thrown at cli/tools/bench/mod.rs:412

              BenchResult::Failed(failure) => {
                report.failed += 1;
                report.failures.push((desc.clone(), failure));
              }
            };
          }

          BenchEvent::UncaughtError(origin, error) => {
            report.failed += 1;
            reporter.report_uncaught_error(&origin, error);
          }
        }
      }

      reporter.report_end(&report);

      if used_only {
        return Err(anyhow!(
          "Bench failed because the \"only\" option was used",
        ));
      }

      if report.failed > 0 {
        return Err(anyhow!("Bench failed"));
      }

      Ok(())
    })
  };

  let (join_results, result) = future::join(join_stream, handler).await;

  // propagate any errors
  for join_result in join_results {
    join_result??;
  }

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Search bench files for 'only: true' and 'Bench.only(' and remove the option so all benchmarks run again
  2. Use 'deno bench --filter=<name>' to focus a single benchmark instead of the only option
  3. Add a pre-commit/CI grep gate for .only( in *_bench.ts files so it never reaches deno bench
  4. Keep the focused run local and never commit the only flag

Example fix

// before
Deno.bench('sort focus', { only: true }, () => { /* ... */ });
// after
Deno.bench('sort focus', () => { /* ... */ });
// focus locally with: deno bench --filter='sort focus'
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# Gate: refuse to run deno bench while any 'only' option is present
if grep -rnE "\.only\(|only:\s*true" --include='*_bench.ts' --include='*.bench.ts' --include='bench.ts' .; then
  echo 'ERROR: bench "only" option present - remove it before running'; exit 1;
fi
deno bench "$@"

Try / catch

# CI: fail with a clear message distinct from real bench failures
deno bench || { rc=$?; grep -q '"only" option' build.log && echo 'someone left bench.only in the tree'; exit $rc; }

Prevention

When it happens

Trigger: Any discovered bench file calls Deno.bench('name', { only: true }, fn) or Bench.only(...); the Plan event sets plan.used_only, and after all events are consumed used_only forces the error.

Common situations: A developer focuses one benchmark locally with only: true and commits it; CI then fails with this message; the flag survives a refactor because removing it is easy to forget.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/509322e5e182aa47. Report an issue: GitHub.