{"record":{"id":"47ba37cf7903efa7","repo":"mochajs/mocha","slug":"err-mocha-invalid-arg-type-47ba37","errorCode":"ERR_MOCHA_INVALID_ARG_TYPE","errorMessage":"Empty `eventName` string argument","messagePattern":"Empty `eventName` string argument","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/nodejs/serializer.js","lineNumber":139,"sourceCode":"export class SerializableEvent {\n  /**\n   * Constructs a `SerializableEvent`, throwing if we receive unexpected data.\n   *\n   * Practically, events emitted from `Runner` have a minimum of zero (0)\n   * arguments-- (for example, {@link Runnable.constants.EVENT_RUN_BEGIN}) and a\n   * maximum of two (2) (for example,\n   * {@link Runnable.constants.EVENT_TEST_FAIL}, where the second argument is an\n   * `Error`).  The first argument, if present, is a {@link Runnable}. This\n   * constructor's arguments adhere to this convention.\n   * @param {string} eventName - A non-empty event name.\n   * @param {any} [originalValue] - Some data. Corresponds to extra arguments\n   * passed to `EventEmitter#emit`.\n   * @param {Error} [originalError] - An error, if there's an error.\n   * @throws If `eventName` is empty, or `originalValue` is a non-object.\n   */\n  constructor(eventName, originalValue, originalError) {\n    if (!eventName) {\n      throw createInvalidArgumentTypeError(\n        \"Empty `eventName` string argument\",\n        \"eventName\",\n        \"string\",\n      );\n    }\n    /**\n     * The event name.\n     * @memberof SerializableEvent\n     */\n    this.eventName = eventName;\n    const originalValueType = type(originalValue);\n    if (originalValueType !== \"object\" && originalValueType !== \"undefined\") {\n      throw createInvalidArgumentTypeError(\n        `Expected object but received ${originalValueType}`,\n        \"originalValue\",\n        \"object\",\n      );\n    }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/nodejs/serializer.js#L121-L157","documentation":"SerializableEvent's constructor (lib/nodejs/serializer.js:139) throws ERR_MOCHA_INVALID_ARG_TYPE when the `eventName` argument is falsy (empty string, null, undefined). The event name is required because it is later re-emitted via EventEmitter#emit on the receiving side. This guards against serializing events that could not be dispatched.","triggerScenarios":"Calling `new SerializableEvent('')`, `new SerializableEvent(null, value)`, or passing an event name that resolves to an empty string from a variable.","commonSituations":"Programmatic use of the parallel-mode serializer API; constructing events dynamically where the name variable is unset or trimmed to empty; library-internal regressions when wiring worker events.","solutions":["Pass a non-empty string as the first argument to SerializableEvent.","Validate/trim the event name variable before construction.","Check the call site for undefined variables or misordered arguments."],"exampleFix":"// before\nnew SerializableEvent(name, payload); // name === ''\n// after\nif (!name) throw new Error('event name required');\nnew SerializableEvent(name, payload);","handlingStrategy":"type-guard","validationCode":"if (typeof eventName !== 'string' || eventName.length === 0) {\n  throw new Error('eventName must be a non-empty string');\n}","typeGuard":"function isValidEventName(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  const evt = new SerializableEvent(eventName, payload);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_INVALID_ARG_TYPE') {\n    console.error('SerializableEvent requires a non-empty eventName string');\n  } else throw err;\n}","preventionTips":["Validate event names at emit sites","Keep event names as constants, not computed empty values"],"tags":["serializer","parallel-mode","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"}