{"record":{"id":"dc2f4336249931ad","repo":"nodejs/node","slug":"und-err-invalid-arg-dc2f43","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"invalid opts","messagePattern":"invalid opts","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/api/api-request.js","lineNumber":14,"sourceCode":"'use strict'\n\nconst assert = require('node:assert')\nconst { AsyncResource } = require('node:async_hooks')\nconst { Readable } = require('./readable')\nconst { InvalidArgumentError, RequestAbortedError } = require('../core/errors')\nconst util = require('../core/util')\n\nfunction noop () {}\n\nclass RequestHandler extends AsyncResource {\n  constructor (opts, callback) {\n    if (!opts || typeof opts !== 'object') {\n      throw new InvalidArgumentError('invalid opts')\n    }\n\n    const { signal, method, opaque, body, onInfo, responseHeaders, highWaterMark } = opts\n\n    try {\n      if (typeof callback !== 'function') {\n        throw new InvalidArgumentError('invalid callback')\n      }\n\n      if (highWaterMark != null && (!Number.isFinite(highWaterMark) || highWaterMark < 0)) {\n        throw new InvalidArgumentError('invalid highWaterMark')\n      }\n\n      if (signal && typeof signal.on !== 'function' && typeof signal.addEventListener !== 'function') {\n        throw new InvalidArgumentError('signal must be an EventEmitter or EventTarget')\n      }\n\n      if (method === 'CONNECT') {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/api/api-request.js#L1-L32","documentation":"Thrown by undici's RequestHandler constructor (the handler behind request()) when opts is null, undefined, or not an object. request() performs a single request and yields a one-shot response body. Code is UND_ERR_INVALID_ARG.","triggerScenarios":"Calling dispatcher.request(url, null, cb) or request(url, undefined, cb) — passing a non-object where the options object is required.","commonSituations":"Optional opts variable that resolved to undefined; passing the callback in the opts slot; reusing fetch-style two-arg signature.","solutions":["Pass an options object (even {}): request(url, {}, cb).","If using the promise form, request(url, opts) with opts defined.","Validate that opts is defined before calling."],"exampleFix":"// before\nawait dispatcher.request(url, undefined)\n// after\nawait dispatcher.request(url, {})","handlingStrategy":"type-guard","validationCode":"function withOpts(o) { return o && typeof o === 'object' ? o : {} }","typeGuard":"function isOptsObject(o: unknown): o is Record<string, unknown> { return !!o && typeof o === 'object' }","tryCatchPattern":"try { await dispatcher.request(url, opts) }\ncatch (err) {\n  if (err.code === 'UND_ERR_INVALID_ARG' && /invalid opts/.test(err.message)) throw new TypeError('request opts must be an object')\n  throw err\n}","preventionTips":["Default opts to {} when none needed.","Validate opts is defined before calling.","Type opts as an object in TypeScript."],"tags":["undici","request","validation","argument","http"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}