{"record":{"id":"4d13801e59a92da3","repo":"nodejs/node","slug":"und-err-invalid-arg-4d1380","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"invalid callback","messagePattern":"invalid callback","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/dispatcher/dispatcher-base.js","lineNumber":66,"sourceCode":"    return this[kDestroyed]\n  }\n\n  /** @returns {boolean} */\n  get closed () {\n    return this[kClosed]\n  }\n\n  close (callback) {\n    if (callback === undefined) {\n      return new Promise((resolve, reject) => {\n        this.close((err, data) => {\n          return err ? reject(err) : resolve(data)\n        })\n      })\n    }\n\n    if (typeof callback !== 'function') {\n      throw new InvalidArgumentError('invalid callback')\n    }\n\n    if (this[kDestroyed]) {\n      const err = new ClientDestroyedError()\n      queueMicrotask(() => callback(err, null))\n      return\n    }\n\n    if (this[kClosed]) {\n      if (this[kOnClosed]) {\n        this[kOnClosed].push(callback)\n      } else {\n        queueMicrotask(() => callback(null, null))\n      }\n      return\n    }\n\n    this[kClosed] = true","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/dispatcher/dispatcher-base.js#L48-L84","documentation":"Thrown by DispatcherBase.close() when the supplied callback is neither undefined nor a function. Passing undefined makes close() return a Promise; passing a function uses the node-style (err, data) callback. Any other type is rejected synchronously with UND_ERR_INVALID_ARG.","triggerScenarios":"Calling `client.close('done')`, `client.close(null)`, `client.close({})`, or `client.close(42)`. Triggered at dispatcher-base.js:65-66.","commonSituations":"Passing a Promise resolve/reject handle incorrectly; passing a string event name by mistake; passing an options object where a callback was expected; refactor that dropped the callback parameter.","solutions":["Call close() with no argument to get a Promise: await client.close().","Pass a node-style callback: client.close((err, data) => { ... }).","Check the call site for a misplaced argument."],"exampleFix":"// before\nclient.close('finished')\n// after\nawait client.close()","handlingStrategy":"type-guard","validationCode":"function closeSafely(client, cb) {\n  if (cb !== undefined && typeof cb !== 'function') {\n    throw new TypeError('close callback must be a function or undefined');\n  }\n  return cb === undefined ? client.close() : client.close(cb);\n}","typeGuard":"callback === undefined || typeof callback === 'function'","tryCatchPattern":"try { client.close(maybeCb); } catch (e) { if (e.code === 'UND_ERR_INVALID_ARG') { await client.close(); } else throw e; }","preventionTips":["Prefer the Promise form: await client.close().","Never pass strings, objects, or null as the callback.","If forwarding an optional callback, default it to undefined, not null."],"tags":["undici","dispatcher","lifecycle","validation","callback"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}