{"record":{"id":"821086f88a2c3e73","repo":"mochajs/mocha","slug":"err-mocha-missing-argument","errorCode":"ERR_MOCHA_MISSING_ARGUMENT","errorMessage":"\"--invert\" requires one of \"--fgrep <str>\" or \"--grep <regexp>\"","messagePattern":"\"--invert\" requires one of \"--fgrep <str>\" or \"--grep <regexp>\"","errorType":"validation","errorClass":"MissingArgumentError","httpStatus":null,"severity":"error","filePath":"lib/cli/run.cjs","lineNumber":91,"sourceCode":"  // \"one-and-dones\"; help and version are handled by the top-level CLI.\n  const oneAndDoneOptions = Object.keys(ONE_AND_DONES).filter((opt) =>\n    Boolean(argv[opt]),\n  );\n  if (oneAndDoneOptions.length > 1) {\n    throw createUnsupportedError(\n      `Arguments ${oneAndDoneOptions.join(\" and \")} are mutually exclusive`,\n    );\n  }\n\n  Object.keys(ONE_AND_DONES).forEach((opt) => {\n    if (argv[opt]) {\n      ONE_AND_DONES[opt].call(null);\n      process.exit(0);\n    }\n  });\n\n  if (argv.invert && !(\"fgrep\" in argv || \"grep\" in argv)) {\n    throw createMissingArgumentError(\n      '\"--invert\" requires one of \"--fgrep <str>\" or \"--grep <regexp>\"',\n      \"--fgrep|--grep\",\n      \"string|regexp\",\n    );\n  }\n\n  if (argv.fgrep && argv.grep) {\n    throw createUnsupportedError(\n      \"Arguments fgrep and grep are mutually exclusive\",\n    );\n  }\n\n  if (argv.parallel) {\n    if (argv.file) {\n      throw createUnsupportedError(\n        \"--parallel runs test files in a non-deterministic order, and is mutually exclusive with --file\",\n      );\n    }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/cli/run.cjs#L73-L109","documentation":"The --invert flag negates the test-file/name filter, so it requires a filter to invert (--grep or --fgrep). validateRunOptions throws createMissingArgumentError when --invert is present but neither filter option is supplied.","triggerScenarios":"Running `mocha --invert` (or passing argv {invert:true}) without also passing --grep <regexp> or --fgrep <str>.","commonSituations":"Editing an npm script and deleting the --grep part but keeping --invert; templated CI scripts where the grep parameter is empty and only --invert survives; typos like --grepp.","solutions":["Add a filter: pass --grep <regexp> or --fgrep <str> alongside --invert","If no filtering is wanted, remove --invert entirely","Fix typos in the flag name so the grep/fgrep value is actually parsed"],"exampleFix":"// before\nmocha --invert\n// after\nmocha --grep \"auth\" --invert","handlingStrategy":"validation","validationCode":"if (argv.invert && !argv.grep && !argv.fgrep) {\n  throw new Error('--invert requires --grep or --fgrep');\n}","typeGuard":null,"tryCatchPattern":"try {\n  mochaRun(argv);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_MISSING_ARGUMENT') {\n    console.error(err.message);\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Always pair --invert with --grep or --fgrep in scripts","Template CI scripts so empty filter values omit both --grep and --invert","Grep your package.json scripts for bare '--invert' occurrences"],"tags":["cli","argument-validation"],"backgroundTag":"missing-required-flag","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}