{"record":{"id":"74313c3feb45778e","repo":"mochajs/mocha","slug":"not-enough-arguments-following-name","errorCode":null,"errorMessage":"Not enough arguments following: ${name}","messagePattern":"Not enough arguments following: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/cli/parse-args.js","lineNumber":304,"sourceCode":"};\n\n/**\n * Disallows multiple arguments after a single option, such as `--grep abc def`.\n */\nconst validateArgsBeforeParse = (allArgs) => {\n  allArgs.forEach((arg, index) => {\n    if (!arg.startsWith(\"-\") || arg === \"--\" || arg.includes(\"=\")) {\n      return;\n    }\n\n    const name = canonicalOptionName(stripLeadingDashes(arg));\n    const next = allArgs[index + 1];\n\n    if (\n      requiresValue(name) &&\n      (next === undefined || (next.startsWith(\"-\") && !isNumeric(next)))\n    ) {\n      throw new Error(`Not enough arguments following: ${name}`);\n    }\n  });\n};\n\nconst normalizeParsedValues = (values, positionals) => {\n  const normalized = Object.assign({ _: positionals }, values);\n\n  Object.keys(normalized).forEach((rawName) => {\n    if (rawName === \"_\") {\n      return;\n    }\n\n    const name = canonicalOptionName(rawName);\n    if (name !== rawName) {\n      normalized[name] = mergeValue(normalized[name], normalized[rawName]);\n      delete normalized[rawName];\n    }\n  });","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/cli/parse-args.js#L286-L322","documentation":"Before handing arguments to yargs, Mocha validates that every option flagged as requiring a value actually has a following argument. `validateArgsBeforeParse` throws this error when an option like `--reporter` or `--timeout` appears at the end of the argument list or is followed by another dash-prefixed token (that isn't a negative number), meaning its value is missing.","triggerScenarios":"`mocha --reporter` (option last with no value); `mocha --timeout --grep foo` (option followed by another flag); `parseMochaArgs(['--require'])`; any option in `requiresValue(name)` whose next token is undefined or starts with '-' and is not numeric like `-1`.","commonSituations":"Typing `mocha --timeout` and forgetting `2000`; copy-pasted commands where a value was dropped; scripts interpolating empty variables (`mocha --reporter $EMPTY`); intentionally trying `--grep -2` works, but `--grep --diff` does not.","solutions":["Supply the option's value: e.g. `mocha --reporter spec`, `mocha --timeout 2000`.","Inspect the full command line for an option sitting at the end or directly before another flag.","In scripts, guard variable expansion: `${REPORTER:-spec}` or fail fast if the variable is unset.","If a value itself legitimately starts with '-', use `--opt=-value` form or reorder arguments."],"exampleFix":"// before\n$ mocha --reporter\n// Error: Not enough arguments following: --reporter\n\n// after\n$ mocha --reporter spec","handlingStrategy":"validation","validationCode":"const VALUE_OPTS = ['--reporter','--timeout','--grep','--require','--ui','--spec','--config','--package','--node-option'];\nfunction validate(argv) {\n  for (let i = 0; i < argv.length; i++) {\n    if (VALUE_OPTS.includes(argv[i])) {\n      const next = argv[i + 1];\n      if (next === undefined || (next.startsWith('-') && !/^-\\d/.test(next))) {\n        throw new Error(`Missing value for ${argv[i]}`);\n      }\n    }\n  }\n}","typeGuard":"const hasValueAfter = (argv, i) => i + 1 < argv.length && !(argv[i + 1].startsWith('-') && !isNumeric(argv[i + 1]));","tryCatchPattern":"try {\n  const { mochaArgs } = parseMochaArgs(rawArgs);\n} catch (err) {\n  if (err.message.startsWith('Not enough arguments following:')) {\n    console.error(err.message + ' — supply a value for the option.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Never end a command line with a value-taking option.","Use `--opt=value` syntax to make value binding explicit.","Guard interpolated script variables: `--reporter \"${REPORTER:-spec}\"`.","Remember negative numbers (e.g. `--timeout -1`) are accepted values, other dash-tokens are not."],"tags":["cli","argument-validation","yargs"],"backgroundTag":"missing-required-cli-argument","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}