{"record":{"id":"6819796148a0ba3b","repo":"nodejs/node","slug":"und-err-invalid-arg-681979","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"socket is required","messagePattern":"socket is required","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/core/socks5-client.js","lineNumber":71,"sourceCode":"  HANDSHAKING: 'handshaking',\n  AUTHENTICATING: 'authenticating',\n  AUTHENTICATED: 'authenticated',\n  CONNECTING: 'connecting',\n  CONNECTED: 'connected',\n  ERROR: 'error',\n  CLOSED: 'closed'\n}\n\n/**\n * SOCKS5 client implementation\n * Handles SOCKS5 protocol negotiation and connection establishment\n */\nclass Socks5Client extends EventEmitter {\n  constructor (socket, options = {}) {\n    super()\n\n    if (!socket) {\n      throw new InvalidArgumentError('socket is required')\n    }\n\n    this.socket = socket\n    this.options = options\n    this.state = STATES.INITIAL\n    this.buffer = EMPTY_BUFFER\n    this.onSocketData = this.onData.bind(this)\n    this.onSocketError = this.onError.bind(this)\n    this.onSocketClose = this.onClose.bind(this)\n\n    // Authentication settings\n    this.authMethods = []\n    if (options.username && options.password) {\n      this.authMethods.push(AUTH_METHODS.USERNAME_PASSWORD)\n    }\n    this.authMethods.push(AUTH_METHODS.NO_AUTH)\n\n    // Socket event handlers","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/core/socks5-client.js#L53-L89","documentation":"Thrown by the Socks5Client constructor when the first argument (socket) is falsy. The class wraps an existing socket to drive the SOCKS5 protocol, so without one there is nothing to read/write. This is a programmer-facing guard, not a network condition.","triggerScenarios":"Constructing `new Socks5Client(null)`, `new Socks5Client(undefined)`, or `new Socks5Client()` (defaulting socket to undefined). Also when a socket variable is conditionally assigned and falls through to undefined before being passed in.","commonSituations":"Refactoring a proxy setup and forgetting to plumb the socket; a connection step that returns null on failure being passed straight into the client; copy-paste from a sample that omitted the socket argument.","solutions":["Ensure the socket argument is a connected (or connecting) net.Socket/duplex stream before instantiating Socks5Client.","Add a guard at the call site so a failed upstream connection does not reach the constructor.","Run a type check or assertion that the socket is non-null and is a Duplex."],"exampleFix":"// before\nconst client = new Socks5Client(maybeSocket)\n\n// after\nif (!maybeSocket) throw new Error('upstream socket unavailable')\nconst client = new Socks5Client(maybeSocket)","handlingStrategy":"validation","validationCode":"function makeSocks5Client(socket, options) {\n  if (!socket || typeof socket.write !== 'function') {\n    throw new Error('a writable socket is required')\n  }\n  return new Socks5Client(socket, options)\n}","typeGuard":"function isDuplexSocket(v) {\n  return v != null && typeof v.write === 'function' && typeof v.on === 'function'\n}","tryCatchPattern":null,"preventionTips":["Construct the client only after the upstream socket is confirmed connected.","Fail fast in your factory function rather than letting undefined propagate.","Run with a type-checker (TS) that flags possibly-undefined socket arguments."],"tags":["socks5","proxy","api-misuse","validation","constructor"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}