{"record":{"id":"63699918f4743c5f","repo":"mochajs/mocha","slug":"err-mocha-invalid-arg-type-636999","errorCode":"ERR_MOCHA_INVALID_ARG_TYPE","errorMessage":"Expected a non-empty filepath","messagePattern":"Expected a non-empty filepath","errorType":"validation","errorClass":"InvalidArgumentTypeError","httpStatus":null,"severity":"error","filePath":"lib/nodejs/buffered-worker-pool.cjs","lineNumber":128,"sourceCode":"  async terminate(force = false) {\n    /* istanbul ignore next */\n    debug(\"terminate(): terminating with force = %s\", force);\n    return this._pool.terminate(force);\n  }\n\n  /**\n   * Adds a test file run to the worker pool queue for execution by a worker process.\n   *\n   * Handles serialization/deserialization.\n   *\n   * @param {string} filepath - Filepath of test\n   * @param {MochaOptions} [options] - Options for Mocha instance\n   * @private\n   * @returns {Promise<SerializedWorkerResult>}\n   */\n  async run(filepath, options = {}) {\n    if (!filepath || typeof filepath !== \"string\") {\n      throw createInvalidArgumentTypeError(\n        \"Expected a non-empty filepath\",\n        \"filepath\",\n        \"string\",\n      );\n    }\n    const serializedOptions = BufferedWorkerPool.serializeOptions(options);\n    const result = await this._pool.exec(\"run\", [filepath, serializedOptions]);\n    return deserialize(result);\n  }\n\n  /**\n   * Returns stats about the state of the worker processes in the pool.\n   *\n   * Used for debugging.\n   *\n   * @private\n   */\n  stats() {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/nodejs/buffered-worker-pool.cjs#L110-L146","documentation":"BufferedWorkerPool.run() validates its filepath argument before dispatching work to a worker pool. It requires a non-empty string; otherwise it throws ERR_MOCHA_INVALID_ARG_TYPE naming filepath as the offending argument.","triggerScenarios":"Calling bufferedWorkerPool.run(undefined/null/''/non-string) — e.g. when a file-glob resolved to nothing or a variable holding the path was not assigned.","commonSituations":"Parallel-mode file resolution producing empty results; programmatic parallel runners passing a bad entry; glob expansion returning an empty array and code doing files[0] on it.","solutions":["Ensure the filepath exists and is a non-empty string before calling run()","Check upstream glob/CLI parsing so an empty match list is handled before dispatch","Wrap run() in try/catch and log/queue the invalid file instead of crashing the pool"],"exampleFix":"// before\nawait pool.run(files[0]); // files may be empty -> undefined\n// after\nconst file = files[0];\nif (typeof file === 'string' && file.length > 0) {\n  await pool.run(file);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof filepath === 'string' && filepath.length > 0) {\n  await pool.run(filepath, options);\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  await pool.run(filepath, options);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_INVALID_ARG_TYPE') {\n    console.error('Invalid filepath passed to worker pool:', filepath);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Validate resolved test file lists before dispatch (length > 0)","Handle empty glob results explicitly","Log the value that failed so upstream resolution bugs surface quickly"],"tags":["mocha","parallel","argument-validation","worker-pool"],"backgroundTag":"invalid-argument-value","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}