{"record":{"id":"dafdce161a2c82f6","repo":"mochajs/mocha","slug":"missing-runner-argument","errorCode":null,"errorMessage":"Missing runner argument","messagePattern":"Missing runner argument","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/reporters/base.js","lineNumber":63,"sourceCode":"/**\n * @abstract\n * @description\n * All other reporters generally inherit from this reporter.\n */\nexport class Base {\n  /**\n   * Constructs a new `Base` reporter instance.\n   *\n   * @public\n   * @memberof Mocha.reporters\n   * @param {Runner} runner - Instance triggers reporter actions.\n   * @param {Object} [options] - runner options\n   */\n  constructor(runner, options) {\n    var failures = (this.failures = []);\n\n    if (!runner) {\n      throw new TypeError(\"Missing runner argument\");\n    }\n    this.options = options || {};\n    this.runner = runner;\n    this.stats = runner.stats; // assigned so Reporters keep a closer reference\n\n    var maxDiffSizeOpt =\n      this.options.reporterOption && this.options.reporterOption.maxDiffSize;\n    if (maxDiffSizeOpt !== undefined && !isNaN(Number(maxDiffSizeOpt))) {\n      Base.maxDiffSize = Number(maxDiffSizeOpt);\n    }\n\n    runner.on(EVENT_TEST_PASS, function (test) {\n      if (test.duration > test.slow()) {\n        test.speed = \"slow\";\n      } else if (test.duration > test.slow() / 2) {\n        test.speed = \"medium\";\n      } else {\n        test.speed = \"fast\";","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/reporters/base.js#L45-L81","documentation":"The `Base` reporter constructor requires a runner instance as its first argument because it immediately reads `runner.stats`, attaches event listeners, and tracks failures. A `TypeError` is thrown when the reporter is instantiated without one, which almost always means Mocha internals were wired incorrectly.","triggerScenarios":"`new (require('mocha/lib/reporters/base'))()` with no runner; instantiating a custom reporter directly without passing the runner; a wrapper/adapter class forgetting to forward the runner to `super()`.","commonSituations":"Custom reporters calling `super()` without forwarding `runner`; test tooling that constructs reporters manually outside of `mocha.run()`; framework integrations creating a reporter before the runner exists.","solutions":["Always pass the runner: `new MyReporter(runner, options)`.","In custom reporter subclasses, forward arguments to the base class: `constructor(runner, options) { super(runner, options); ... }`.","Let Mocha instantiate reporters via `new Mocha({reporter: 'spec'}).run()` instead of constructing them yourself."],"exampleFix":"// before\nconstructor(options) {\n  super(); // TypeError: Missing runner argument\n}\n\n// after\nconstructor(runner, options) {\n  super(runner, options);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof runner === 'undefined' || runner === null) {\n  throw new TypeError('Cannot create reporter: runner is required');\n}","typeGuard":"const isRunner = (r) => r != null && typeof r.on === 'function' && typeof r.emit === 'function';","tryCatchPattern":"try {\n  const reporter = new Base(runner, options);\n} catch (err) {\n  if (err instanceof TypeError && err.message === 'Missing runner argument') {\n    console.error('Reporter requires a runner from mocha.run()');\n  }\n  throw err;\n}","preventionTips":["Always forward constructor args to super() in custom reporters.","Construct reporters via Mocha's public API rather than by hand.","Validate the runner exists before instantiating reporters in tooling.","Type reporters as (runner: Mocha.Runner, options?: any) so TS catches missing args."],"tags":["reporters","argument-validation","typeerror"],"backgroundTag":"missing-required-argument","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}