{"record":{"id":"c806e30335e85921","repo":"denoland/deno","slug":"unexpected-fn-field-in-options-bench-function-i","errorCode":null,"errorMessage":"Unexpected 'fn' field in options, bench function is already provided as the third argument","messagePattern":"Unexpected 'fn' field in options, bench function is already provided as the third argument","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cli/js/40_bench.js","lineNumber":125,"sourceCode":"    ignore: false,\n    baseline: false,\n    only: false,\n    sanitizeExit: true,\n    permissions: null,\n  };\n\n  if (typeof nameOrFnOrOptions === \"string\") {\n    if (!nameOrFnOrOptions) {\n      throw new TypeError(\"The bench name can't be empty\");\n    }\n    if (typeof optionsOrFn === \"function\") {\n      benchDesc = { fn: optionsOrFn, name: nameOrFnOrOptions, ...defaults };\n    } else {\n      if (!maybeFn || typeof maybeFn !== \"function\") {\n        throw new TypeError(\"Missing bench function\");\n      }\n      if (optionsOrFn.fn != undefined) {\n        throw new TypeError(\n          \"Unexpected 'fn' field in options, bench function is already provided as the third argument\",\n        );\n      }\n      if (optionsOrFn.name != undefined) {\n        throw new TypeError(\n          \"Unexpected 'name' field in options, bench name is already provided as the first argument\",\n        );\n      }\n      benchDesc = {\n        ...defaults,\n        ...optionsOrFn,\n        fn: maybeFn,\n        name: nameOrFnOrOptions,\n      };\n    }\n  } else if (typeof nameOrFnOrOptions === \"function\") {\n    if (!nameOrFnOrOptions.name) {\n      throw new TypeError(\"The bench function must have a name\");","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/js/40_bench.js#L107-L143","documentation":"Before formatting, `read_file_contents` reads the raw bytes, records whether a UTF-8 BOM is present, detects the charset, and decodes via `decode_owned_source`. When decoding fails, the file contains byte sequences that are not valid UTF-8 under the detected charset, and fmt refuses to touch it because it cannot round-trip the text safely.","triggerScenarios":"A file matched by the formatter glob contains invalid UTF-8: a binary file with a source-like extension, or a text file saved in a legacy single-byte encoding (Latin-1, Windows-1252, Shift-JIS) without a BOM/charset declaration, so charset detection falls through to UTF-8 and decoding fails.","commonSituations":"Files created by Windows tools in ANSI encoding; CSV/data fixtures with non-UTF8 bytes accidentally matching fmt includes; a binary accidentally named `.json`/`.ts`; files corrupted by a bad patch or transfer.","solutions":["Re-save the file as UTF-8: `iconv -f WINDOWS-1252 -t UTF-8 file.ts > file.fixed && mv file.fixed file.ts` (or use the editor's 'Save with Encoding')","If the file is binary or a data fixture, exclude it via `\"fmt\": { \"exclude\": [...] }` in deno.json or `--ignore`","Verify with `file file.ts` / a UTF-8 validator which files are invalid before re-running fmt"],"exampleFix":"# before\n$ deno fmt data/legacy.ts\n# Error reading .../legacy.ts: ... is not a valid UTF-8 file\n\n# after\n$ iconv -f WINDOWS-1252 -t UTF-8 data/legacy.ts > /tmp/fixed.ts && mv /tmp/fixed.ts data/legacy.ts\n$ deno fmt  # ok","handlingStrategy":"validation","validationCode":"// Pre-check every file fmt will touch decodes as strict UTF-8\nfor (const f of files) {\n  const bytes = await Deno.readFile(f);\n  try {\n    new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n  } catch {\n    console.error(`not UTF-8: ${f} — convert or exclude it`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save sources as UTF-8 (no BOM needed) and set editor encoding accordingly","Keep binary/data files out of directories fmt scans, or add them to fmt exclude","After converting legacy-encoded files, validate with `iconv -t UTF-8 file > /dev/null` before committing"],"tags":["encoding","utf-8","formatting","fmt"],"backgroundTag":"non-utf8-file-encoding","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T04:17:50.494Z"}