denoland/deno · error
Bench failed
Error message
Bench failed
What it means
`deno bench` exits with this error when at least one bench reported an uncaught error (`report.failed > 0`) — the bench body threw, or the bench module failed during load/registration. The per-failure details are printed by the reporter above this final message.
Solutions
- Read the 'error:' blocks printed above the summary — they name the origin module and the error for each failed bench
- Reproduce a single failing bench with `deno bench --filter <name>`
- Fix the throwing setup/body (validate env/files before benching); if the module itself fails to load, run it with `deno run` to see the original stack trace
Example fix
// before
Deno.bench("api", async () => {
const key = Deno.env.get("API_KEY")!.length; // throws if unset
});
// after
Deno.bench("api", async () => {
const key = Deno.env.get("API_KEY");
if (!key) throw new Error("API_KEY must be set for this bench");
// ...
}); Defensive patterns
Strategy: try-catch
Try / catch
Wrap only the environment-dependent setup of a bench in try/catch and fail with a descriptive message; let assertions inside the measured body throw so the bench is still correctly counted as failed.
Prevention
- Validate env vars and input files in shared setup before any bench body runs
- Reproduce single failures with `deno bench --filter <name>`
- Run the bench module with `deno run` when load-time errors are suspected
When it happens
Trigger: A bench function throws (assertion failure, runtime error), or a bench module raises during registration; a `BenchEvent::UncaughtError` increments the failure count and the run terminates with 'Bench failed'.
Common situations: Bench setup that depends on missing env vars, files, or ports; assertion helpers throwing inside bench bodies; a bench module importing something unavailable in the bench environment.
Related errors
- Bench failed because the "only" option was used
- ERR_ASSERTION
- ERR_ASSERTION
- ERR_INVALID_ARG_VALUE
- ERR_INVALID_OBJECT_DEFINE_PROPERTY
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/00ac2af89bbcfdf2.
Report an issue: GitHub.
Appendix: 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 9ad36f7a2c)