denoland/deno · error

Bench failed

Error message

Bench failed

What it means

The terminal 'Bench failed' error: report.failed > 0 after all bench events were consumed (cli/tools/bench/mod.rs:417-419). A benchmark body threw, a BenchResult::Failed was recorded, or an UncaughtError escaped a bench module. The specific failures were already printed by the reporter in the failures section above this message; this error only converts them into a non-zero exit code.

Source

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

          }

          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??;
  }

  result??;

  Ok(())
}

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Read the failures section of the bench output above the error - it names the bench and the thrown error
  2. Fix the throwing assertion or operation inside the named benchmark
  3. If the failure is environmental (network, tmp files), make the bench self-contained or skip it via --filter/--ignore
  4. Run 'deno bench --filter=<name>' to iterate on just the failing benchmark

Example fix

// before: bench that can throw on transient state
Deno.bench('db query', () => { assertQueryResult(runQuery()); });
// after: bench guarded internally, failures asserted explicitly
Deno.bench('db query', () => {
  const r = runQuery();
  if (!r.ok) throw new Error(`query failed: ${r.err}`);
});
Defensive patterns

Strategy: try-catch

Validate before calling

// Keep benches deterministic: assert explicitly instead of letting ops throw
Deno.bench('stable-metric', () => {
  const value = computeMetric();
  if (!Number.isFinite(value)) throw new Error(`metric not finite: ${value}`);
});

Try / catch

# CI wrapper: capture the failures section for a useful annotation on red builds
deno bench 2>&1 | tee bench.log; rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ]; then
  sed -n '/failures:/,$p' bench.log || true
fi
exit $rc

Prevention

When it happens

Trigger: A bench fn throws or an assertion inside it fails (BenchResult::Failed); an uncaught error escapes during module load or between benches (BenchEvent::UncaughtError increments report.failed); teardown code panics.

Common situations: Benchmarks that assert performance thresholds (noshuffle iteration counts, ops/sec floors) flaking under CI load; benches touching the network or filesystem where an operation intermittently throws; module-level code in a *_bench.ts file throwing at import time.

Related errors


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