{"record":{"id":"2f746c3737f10753","repo":"nodejs/node","slug":"connect-must-be-a-function-or-an-object","errorCode":null,"errorMessage":"connect must be a function or an object","messagePattern":"connect must be a function or an object","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/dispatcher/round-robin-pool.js","lineNumber":53,"sourceCode":"    tls,\n    maxCachedSessions,\n    socketPath,\n    autoSelectFamily,\n    autoSelectFamilyAttemptTimeout,\n    allowH2,\n    clientTtl,\n    ...options\n  } = {}) {\n    if (connections != null && (!Number.isFinite(connections) || connections < 0)) {\n      throw new InvalidArgumentError('invalid connections')\n    }\n\n    if (typeof factory !== 'function') {\n      throw new InvalidArgumentError('factory must be a function.')\n    }\n\n    if (connect != null && typeof connect !== 'function' && typeof connect !== 'object') {\n      throw new InvalidArgumentError('connect must be a function or an object')\n    }\n\n    if (typeof connect !== 'function') {\n      connect = buildConnector({\n        ...tls,\n        maxCachedSessions,\n        allowH2,\n        socketPath,\n        timeout: connectTimeout,\n        ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),\n        ...connect\n      })\n    }\n\n    super()\n\n    this[kConnections] = connections || null\n    this[kUrl] = util.parseOrigin(origin)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/dispatcher/round-robin-pool.js#L35-L71","documentation":"Thrown by the RoundRobinPool constructor when connect is present but neither a function nor an object. As with Pool, connect may be a custom connector function or a plain options object fed to buildConnector; any other type is rejected. Guard: connect != null && typeof connect !== 'function' && typeof connect !== 'object'.","triggerScenarios":"Passing connect as a string URL, a number, an array, or a non-plain object. The check fires only when connect is non-null, so omitting it is safe.","commonSituations":"Mistaking connect for a host:port string; passing a TLS bag under the wrong key; JSON config decoding connect to a string; refactoring that wrapped the connector.","solutions":["Pass connect as a function (custom connector) or a plain object (connector/TLS options).","Route host/port/socket config to the correct keys (socketPath, tls, etc.).","Ensure deserialized config yields an object for connect.","Omit connect to let RoundRobinPool build the default connector."],"exampleFix":"// before\nnew RoundRobinPool(url, { connect: 'upstream.local:443' })\n// after\nnew RoundRobinPool(url, { connect: { rejectUnauthorized: true } })","handlingStrategy":"type-guard","validationCode":"if (cfg.connect != null && typeof cfg.connect !== 'function' && typeof cfg.connect !== 'object') {\n  throw new TypeError('connect must be a function or object')\n}\nnew RoundRobinPool(url, { connect: cfg.connect })","typeGuard":"function isValidConnect(v) {\n  return v == null || typeof v === 'function' || (typeof v === 'object' && !Array.isArray(v))\n}","tryCatchPattern":null,"preventionTips":["Do not pass URLs/ports as connect.","Keep TLS options under tls or connect (object form).","Ensure JSON config decodes connect to an object."],"tags":["undici","round-robin-pool","connect","tls","invalid-arg"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}