{"record":{"id":"760177c6e7eeac49","repo":"mochajs/mocha","slug":"not-enough-non-option-arguments-got-0-need-at-le","errorCode":null,"errorMessage":"Not enough non-option arguments: got 0, need at least 1","messagePattern":"Not enough non-option arguments: got 0, need at least 1","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/cli/init.js","lineNumber":18,"sourceCode":"/**\n * Command module for \"init\" command\n *\n * @private\n * @module\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nexport const command = \"init <path>\";\n\nexport const description = \"create a client-side Mocha setup at <path>\";\n\nexport const parse = (args) => {\n  const [pathArg] = args;\n  if (!pathArg) {\n    throw new Error(\"Not enough non-option arguments: got 0, need at least 1\");\n  }\n  return { _: [], path: path.normalize(pathArg) };\n};\n\nexport const handler = (argv) => {\n  const destdir = argv.path;\n  const srcdir = path.join(import.meta.dirname, \"..\", \"..\");\n  fs.mkdirSync(destdir, { recursive: true });\n  const css = fs.readFileSync(path.join(srcdir, \"mocha.css\"));\n  const js = fs.readFileSync(path.join(srcdir, \"mocha.js\"));\n  const tmpl = fs.readFileSync(\n    path.join(srcdir, \"lib\", \"browser\", \"template.html\"),\n  );\n  fs.writeFileSync(path.join(destdir, \"mocha.css\"), css);\n  fs.writeFileSync(path.join(destdir, \"mocha.js\"), js);\n  fs.writeFileSync(path.join(destdir, \"tests.spec.js\"), \"\");\n  fs.writeFileSync(path.join(destdir, \"index.html\"), tmpl);\n};","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/cli/init.js#L1-L36","documentation":"The `mocha init` command requires exactly one positional argument: the destination path where the client-side Mocha setup (browser test scaffolding) will be created. The public `parse` function in lib/cli/init.js destructures the first argument and throws this error when no path argument was supplied, so it cannot know where to write the files.","triggerScenarios":"Running `mocha init` (or `mocha init --reporter spec` etc.) with zero non-option arguments; also `parse([])` or `parse(['--some-option'])` called programmatically with no positional.","commonSituations":"Developers forgetting the output directory when bootstrapping browser tests; shell quoting issues that swallow the argument (e.g. empty variable expansion like `mocha init $UNSET_PATH`); migrating CI scripts where the path argument was dropped.","solutions":["Pass the destination directory: `mocha init ./tests` (or `mocha init <path>`).","Check shell variable expansion/quoting — echo the command to confirm the path argument is actually present.","If invoking parse() programmatically, pass `parse(['./my/path'])` with at least one string element."],"exampleFix":"// before\n$ mocha init\n// Error: Not enough non-option arguments: got 0, need at least 1\n\n// after\n$ mocha init ./test-browser","handlingStrategy":"validation","validationCode":"const args = process.argv.slice(2);\nif (args.length < 1 || args[0].startsWith('-')) {\n  console.error('Usage: mocha init <path>');\n  process.exit(1);\n}","typeGuard":"const hasPathArg = (args) => Array.isArray(args) && typeof args[0] === 'string' && args[0].length > 0;","tryCatchPattern":"try {\n  init.parse(process.argv.slice(3));\n} catch (err) {\n  if (err.message.startsWith('Not enough non-option arguments')) {\n    console.error('Usage: mocha init <path>');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Always pass a destination path to `mocha init`.","Wrap CLI invocations in scripts that assert argument counts before exec.","Beware unset shell variables in CI: use `${VAR:?msg}` to fail loudly.","Check `mocha init --help` for expected usage."],"tags":["cli","argument-validation","init"],"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"}