denoland/deno · error · TypeError
Missing bench function
Error message
Missing bench function
What it means
This is `deno fmt`'s summary error for files that could not be formatted at all, as opposed to files that merely need formatting. Per-file failures (parse errors, unreadable files, decode failures) increment `failed_files_count`, and `finish()` reports how many of the checked files errored. The details of each failure are printed above the summary during the run.
Source
Thrown at cli/js/40_bench.js:122
let benchDesc;
const defaults = {
ignore: false,
baseline: false,
only: false,
sanitizeExit: true,
permissions: null,
};
if (typeof nameOrFnOrOptions === "string") {
if (!nameOrFnOrOptions) {
throw new TypeError("The bench name can't be empty");
}
if (typeof optionsOrFn === "function") {
benchDesc = { fn: optionsOrFn, name: nameOrFnOrOptions, ...defaults };
} else {
if (!maybeFn || typeof maybeFn !== "function") {
throw new TypeError("Missing bench function");
}
if (optionsOrFn.fn != undefined) {
throw new TypeError(
"Unexpected 'fn' field in options, bench function is already provided as the third argument",
);
}
if (optionsOrFn.name != undefined) {
throw new TypeError(
"Unexpected 'name' field in options, bench name is already provided as the first argument",
);
}
benchDesc = {
...defaults,
...optionsOrFn,
fn: maybeFn,
name: nameOrFnOrOptions,
};
}View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Run `deno fmt` without `--check` and read the per-file error lines printed above the summary; fix the reported syntax error
- Isolate the broken file with `deno fmt path/to/file.ts` to see its full error
- Search for leftover conflict markers (`grep -rn '<<<<<<<'`) after a messy merge
- If the file should not be formatted, exclude it via `"fmt": { "exclude": [...] }` in deno.json
Example fix
# before $ deno fmt # Error formatting .../broken.ts: Unexpected token # Failed to format 1 of 12 checked files # after (fix the syntax error in broken.ts, e.g. remove stray comma) $ deno fmt # ok
Defensive patterns
Strategy: try-catch
Validate before calling
# Surface per-file errors before the summary by running fmt verbosely deno fmt 2>&1 | grep -B1 'Error formatting' || true
Try / catch
In scripts wrapping the CLI, run fmt without --check, capture exit code, and treat 'Failed to format N of M' as a per-file error signal: re-run `deno fmt <file>` for each file named above the summary to get the underlying syntax error, fix it, then retry the full run.
Prevention
- Run `deno fmt` locally before pushing so syntax errors surface immediately
- Configure editors to format-on-save with deno
- After merges, grep for conflict markers (`<<<<<<<`) which break parsing
- Keep JSON fixtures either valid or excluded from fmt
When it happens
Trigger: Any matched file raises while formatting: a TypeScript/JavaScript/JSON/JSONC/Markdown file with a syntax error the dprint plugin cannot parse, a file that cannot be read (permissions), or a file whose contents cannot be decoded. Note the summary counts both, so run without `--check` to see each per-file error message.
Common situations: A half-finished refactor left a syntax error in a file that fmt scans; a JSON file with trailing commas or comments outside the configured plugin expectations; a file locked by another process on Windows; merge-conflict markers (`<<<<<<<`) left in a source file.
Related errors
- The bench name can't be empty
- Unexpected 'fn' field in options, bench function is already
- Panic formatting: {}
- Did not format non-workspace directory. Run again specifying
- Formatting succeeded initially, but failed when ensuring a s
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/ecd73a132d022fdc.
Report an issue: GitHub.