{"record":{"id":"8ac6b2cb2a31bac9","repo":"mochajs/mocha","slug":"err-mocha-invalid-arg-value","errorCode":"ERR_MOCHA_INVALID_ARG_VALUE","errorMessage":"invalid reporter option '${opt}'","messagePattern":"invalid reporter option '(.+?)'","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/cli/run.cjs","lineNumber":38,"sourceCode":"  validateLegacyPlugin,\n  runMocha,\n} = require(\"./run-helpers.cjs\");\nconst { ONE_AND_DONES } = require(\"./one-and-dones.js\");\nconst debug = require(\"debug\")(\"mocha:cli:run\");\n\nexports.command = [\"$0 [spec..]\", \"inspect\"];\n\nexports.describe = \"Run tests with Mocha\";\n\nconst camelCase = (name) =>\n  name.replace(/-([a-z])/g, (_, char) => char.toUpperCase());\n\nconst coerceReporterOption = (opts) =>\n  list(opts).reduce((acc, opt) => {\n    const pair = opt.split(\"=\");\n\n    if (pair.length > 2 || !pair.length) {\n      throw createInvalidArgumentValueError(\n        `invalid reporter option '${opt}'`,\n        \"--reporter-option\",\n        opt,\n        'expected \"key=value\" format',\n      );\n    }\n\n    acc[pair[0]] = pair.length === 2 ? pair[1] : true;\n    return acc;\n  }, {});\n\nconst normalizeRunOptions = (argv) => {\n  Object.keys(argv).forEach((name) => {\n    const reporterOptionMatch = name.match(/^reporter-options?\\.(.+)$/);\n    if (reporterOptionMatch) {\n      argv[\"reporter-option\"] = Object.assign({}, argv[\"reporter-option\"], {\n        [reporterOptionMatch[1]]: argv[name],\n      });","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/cli/run.cjs#L20-L56","documentation":"Reporter options passed via --reporter-option (-O) must be key=value pairs. coerceReporterOption splits each option on '=' and throws ERR_MOCHA_INVALID_ARG_VALUE if the value doesn't look like 'key=value' (more than one '=' and no proper pairing). This ensures reporter options arrive as a clean object.","triggerScenarios":"Running `mocha --reporter xunit --reporter-option output` (no =), `--reporter-option a=b=c` (more than one =), or passing malformed entries in the list form of reporter options programmatically.","commonSituations":"Passing a JSON blob as one option string; quoting mistakes in shell dropping the '='; reporters that need nested/comma values — users writing key:value instead of key=value; forgetting that repeated flags or comma lists are the supported shapes.","solutions":["Write options as key=value: `--reporter-option output=report.xml`.","For multiple options, repeat the flag (`-O key1=v1 -O key2=v2`) or comma-separate (`-O key1=v1,key2=v2`) if the value contains no '='.","If a value must contain '=', check the specific reporter's docs for its escaping/delimiter support.","Programmatically, pass reporterOptions as an object instead of the string list form to bypass coercion entirely."],"exampleFix":"// before\nmocha --reporter mochawesome --reporter-option reportDir:reports\n// after\nmocha --reporter mochawesome --reporter-option reportDir=reports","handlingStrategy":"validation","validationCode":"function assertReporterOption(opt) {\n  const pair = opt.split('=');\n  if (pair.length !== 2 || !pair[0]) {\n    throw new Error(`invalid reporter option '${opt}': expected \"key=value\" format`);\n  }\n}\n['output=report.xml'].forEach(assertReporterOption);","typeGuard":"function isKeyValueOption(s) {\n  const parts = s.split('=');\n  return parts.length === 2 && parts[0].length > 0;\n}","tryCatchPattern":"try {\n  execSync('npx mocha -O ' + opts, {stdio: 'inherit'});\n} catch (err) {\n  if (String(err.stderr).includes('invalid reporter option')) {\n    console.error('Use key=value form for --reporter-option');\n  }\n}","preventionTips":["Always quote full key=value args in shell to avoid '=' dropping","Repeat -O per option instead of inventing separators","Pass reporterOptions as an object when constructing Mocha programmatically","Consult the target reporter's docs for multi-value option syntax"],"tags":["cli","reporter-options","arguments","validation"],"backgroundTag":"invalid-cli-option-format","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}