{"record":{"id":"7c35aeccfe5717c9","repo":"mochajs/mocha","slug":"err-mocha-invalid-arg-type-7c35ae","errorCode":"ERR_MOCHA_INVALID_ARG_TYPE","errorMessage":"Expected a non-empty \"filepath\" argument","messagePattern":"Expected a non-empty \"filepath\" argument","errorType":"validation","errorClass":"InvalidArgumentTypeError","httpStatus":null,"severity":"error","filePath":"lib/nodejs/worker.cjs","lineNumber":71,"sourceCode":"  });\n  validateLegacyPlugin(argv, \"ui\", Mocha.interfaces);\n\n  rootHooks = plugins.rootHooks;\n  bootstrap = () => {};\n  debug(\"bootstrap(): finished with args: %O\", argv);\n};\n\n/**\n * Runs a single test file in a worker thread.\n * @param {string} filepath - Filepath of test file\n * @param {string} [serializedOptions] - **Serialized** options. This string will be eval'd!\n * @see https://npm.im/serialize-javascript\n * @returns {Promise<{failures: number, events: BufferedEvent[]}>} - Test\n * failure count and list of events.\n */\nasync function run(filepath, serializedOptions = \"{}\") {\n  if (!filepath) {\n    throw createInvalidArgumentTypeError(\n      'Expected a non-empty \"filepath\" argument',\n      \"file\",\n      \"string\",\n    );\n  }\n\n  debug(\"run(): running test file %s\", filepath);\n\n  if (typeof serializedOptions !== \"string\") {\n    throw createInvalidArgumentTypeError(\n      \"run() expects second parameter to be a string which was serialized by the `serialize-javascript` module\",\n      \"serializedOptions\",\n      \"string\",\n    );\n  }\n  let argv;\n  try {\n    argv = eval(\"(\" + serializedOptions + \")\");","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/nodejs/worker.cjs#L53-L89","documentation":"The worker-side run() function (executed inside the worker process) validates that a filepath was provided before loading the test file. An empty/undefined filepath throws ERR_MOCHA_INVALID_ARG_TYPE with parameter name 'file'.","triggerScenarios":"Calling worker.run('') or worker.run(undefined), or a worker receiving a truncated/incorrect message where the filepath argument is missing.","commonSituations":"Direct/programmatic use of lib/nodejs/worker; protocol bugs in worker messaging; empty glob expansion upstream.","solutions":["Pass a valid non-empty string filepath to run()","Fix upstream code that resolves test files so it never dispatches empty paths","Align mocha versions if the error appears during normal --parallel runs"],"exampleFix":"// before\nworker.run(filePath); // filePath could be ''\n// after\nif (typeof filePath === 'string' && filePath) {\n  await worker.run(filePath);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof filepath === 'string' && filepath) {\n  await worker.run(filepath, serializedOptions);\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  await worker.run(filepath, serializedOptions);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_INVALID_ARG_TYPE') {\n    console.error('worker.run received invalid filepath:', filepath);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Never dispatch empty/undefined filepaths to workers","Fix file resolution upstream so empty matches are filtered","Use BufferedWorkerPool rather than raw worker.run()"],"tags":["mocha","parallel","worker","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}