{"record":{"id":"49faab78f45482b0","repo":"nodejs/node","slug":"und-err-invalid-arg-49faab","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-connect.js","lineNumber":12,"sourceCode":"'use strict'\n\nconst assert = require('node:assert')\nconst { AsyncResource } = require('node:async_hooks')\nconst { InvalidArgumentError, SocketError } = require('../core/errors')\nconst util = require('../core/util')\nconst { addSignal, removeSignal } = require('./abort-signal')\n\nclass ConnectHandler extends AsyncResource {\n  constructor (opts, callback) {\n    if (!opts || typeof opts !== 'object') {\n      throw new InvalidArgumentError('invalid opts')\n    }\n\n    if (typeof callback !== 'function') {\n      throw new InvalidArgumentError('invalid callback')\n    }\n\n    const { signal, opaque, responseHeaders } = opts\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    super('UNDICI_CONNECT')\n\n    this.opaque = opaque || null\n    this.responseHeaders = responseHeaders || null\n    this.callback = callback\n    this.abort = null","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/api/api-connect.js#L1-L30","documentation":"Thrown by undici's ConnectHandler constructor when the opts argument to connect() is null, undefined, or not an object. connect() is the low-level CONNECT-tunnel API (undici.connect). Code is UND_ERR_INVALID_ARG.","triggerScenarios":"Calling undici.connect(null, cb), connect(undefined, cb), or connect('host:port', cb) — passing anything but a plain options object as the first argument.","commonSituations":"Assuming connect takes a URL string like fetch does; passing undefined because the opts variable was never assigned; reusing a fetch-style call signature.","solutions":["Pass a plain options object: connect({ path: 'example.com:443' }, handler).","Required fields go inside opts (e.g. path/destination, signal, opaque).","Check that the variable holding opts is actually defined and is an object before the call."],"exampleFix":"// before\nundici.connect('example.com:443', cb)\n// after\nundici.connect({ path: 'example.com:443' }, cb)","handlingStrategy":"type-guard","validationCode":"function assertConnectOpts(o) { if (!o || typeof o !== 'object') throw new TypeError('connect opts must be an object') }","typeGuard":"function isConnectOpts(o: unknown): o is Record<string, unknown> { return !!o && typeof o === 'object' }","tryCatchPattern":"undici.connect(opts, (err, data) => {\n  if (err && err.code === 'UND_ERR_INVALID_ARG') console.error('bad connect opts:', err.message)\n})","preventionTips":["connect takes an opts object, not a URL string.","Required destination goes in opts.path.","Type the first arg as an object in TypeScript."],"tags":["undici","connect","tunnel","validation","argument"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}