{"record":{"id":"785bb6234a42e82a","repo":"nodejs/node","slug":"und-err-invalid-arg-785bb6","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"Argument dispatcher must implement dispatch","messagePattern":"Argument dispatcher must implement dispatch","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/dispatcher/dispatcher1-wrapper.js","lineNumber":70,"sourceCode":"  }\n\n  onRequestSent () {\n    this.#handler.onRequestSent?.()\n  }\n\n  onResponseStarted () {\n    this.#handler.onResponseStarted?.()\n  }\n}\n\nclass Dispatcher1Wrapper extends Dispatcher {\n  #dispatcher\n\n  constructor (dispatcher) {\n    super()\n\n    if (!dispatcher || typeof dispatcher.dispatch !== 'function') {\n      throw new InvalidArgumentError('Argument dispatcher must implement dispatch')\n    }\n\n    this.#dispatcher = dispatcher\n  }\n\n  static wrapHandler (handler) {\n    if (!handler || typeof handler !== 'object') {\n      throw new InvalidArgumentError('handler must be an object')\n    }\n\n    if (typeof handler.onRequestStart === 'function') {\n      return handler\n    }\n\n    return new LegacyHandlerWrapper(handler)\n  }\n\n  dispatch (opts, handler) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/dispatcher/dispatcher1-wrapper.js#L52-L88","documentation":"InvalidArgumentError (UND_ERR_INVALID_ARG) thrown by the Dispatcher1Wrapper constructor when the supplied dispatcher is null/undefined or lacks a dispatch function. Dispatcher1Wrapper adapts a v1 dispatcher/handler surface for legacy consumers, so it requires a real dispatcher object exposing dispatch().","triggerScenarios":"Constructing `new Dispatcher1Wrapper(null)`, `new Dispatcher1Wrapper({})`, or `new Dispatcher1Wrapper({ dispatch: 'no' })`. Fires at dispatcher1-wrapper.js:69-70.","commonSituations":"Passing a plain handler object where the dispatcher is expected; passing an Agent/Client that failed to construct (so undefined); mixing up the constructor argument order; wrapping an object that mimics a dispatcher but names its method differently.","solutions":["Pass an undici dispatcher instance (Client, Pool, Agent) which implements dispatch.","If wrapping a custom object, ensure it exposes a dispatch(opts, handler) function.","Check the argument is non-null and has typeof .dispatch === 'function' before construction."],"exampleFix":"// before\nnew Dispatcher1Wrapper({ handle() {} })\n// after\nconst { Agent } = require('undici')\nnew Dispatcher1Wrapper(new Agent())","handlingStrategy":"type-guard","validationCode":"function wrapDispatcher1(dispatcher) {\n  if (!dispatcher || typeof dispatcher.dispatch !== 'function') {\n    throw new TypeError('dispatcher must implement dispatch(opts, handler)');\n  }\n  return new Dispatcher1Wrapper(dispatcher);\n}","typeGuard":"!!dispatcher && typeof dispatcher.dispatch === 'function'","tryCatchPattern":null,"preventionTips":["Pass a real undici dispatcher (Client/Pool/Agent) to Dispatcher1Wrapper.","Do not pass handler objects or plain config objects where a dispatcher is expected.","Validate the dispatch method exists before wrapping."],"tags":["undici","dispatcher","wrapper","validation","legacy"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}