{"record":{"id":"35ae536adc9d7ee2","repo":"denoland/deno","slug":"err-invalid-arg-type-35ae53","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"name\" argument must be of type string. Received ${name}","messagePattern":"The \"name\" argument must be of type string\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_tls_wrap.js","lineNumber":1062,"sourceCode":"    // called (e.g. by net.Socket.resume), we need to stop and restart to\n    // pick up the new interceptor callback.\n    tcpHandle.readStop();\n    tcpHandle.readStart();\n  }\n\n  // Kick-start the TLS readable side. During start(), the handshake cycle\n  // may have received and processed a close_notify (peer called end() before\n  // we set up event listeners). The decrypted EOF is buffered in pending_eof\n  // because inner.onread wasn't set yet. Call readStart() directly on the\n  // TLSWrap to install onread and flush any pending data/EOF.\n  if (this._handle) {\n    this._handle.readStart();\n  }\n};\n\nTLSSocket.prototype.setServername = function (name) {\n  if (typeof name !== \"string\") {\n    throw new ERR_INVALID_ARG_TYPE(\"name\", \"string\", name);\n  }\n  if (this._tlsOptions?.isServer) {\n    throw new ERR_TLS_SNI_FROM_SERVER();\n  }\n  this._handle?.setServername(name);\n};\n\n// Format prefixes for the synthetic session buffers we emit from\n// onConnectSecure when rustls handles resumption internally. The encoded\n// payload is `${servername ?? host ?? \"\"}:${port ?? \"\"}` -- see the\n// matching emit sites in onConnectSecure.\nconst SYNTHETIC_SESSION_PREFIXES = [\n  \"deno-tls12-session:\",\n  \"deno-tls13-session-ticket-1:\",\n  \"deno-tls13-session-ticket-2:\",\n  \"deno-tls13-dummy-session:\",\n];\n","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_tls_wrap.js#L1044-L1080","documentation":"TLSSocket.prototype.setServername requires the SNI hostname to be a string (ext/node/polyfills/_tls_wrap.js:1062). Passing a number, null, undefined, or any non-string triggers ERR_INVALID_ARG_TYPE with name 'name' before the value reaches the underlying handle. This is the client-side SNI setter, typically called from a checkServerIdentity or connect callback or by libraries that set the hostname after socket creation.","triggerScenarios":"tlsSocket.setServername(undefined), setServername(host) where host came from URL parsing that produced undefined, or feeding net.isIP-validated values / numbers into it.","commonSituations":"Code deriving the servername from configuration that may be absent (env var not set, options.host undefined); passing an IP address string is accepted by this check but belongs to a separate validation path; upgrading old code that relied on implicit coercion of numbers or objects to strings.","solutions":["Ensure the value is a string before calling: if (typeof name === 'string') tlsSocket.setServername(name)","Fix the upstream source of the value — usually options.host or options.servername that was never set","Prefer passing servername in tls.connect({ servername }) so the runtime sets it during handshake instead of calling setServername manually"],"exampleFix":"// before\nsocket.setServername(options.host); // host may be undefined\n\n// after\nconst servername = typeof options.host === 'string' ? options.host : undefined;\nif (servername) socket.setServername(servername);","handlingStrategy":"type-guard","validationCode":"if (typeof name !== 'string' || name === '') throw new TypeError('servername must be a non-empty string');","typeGuard":"function isServername(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { socket.setServername(name); } catch (e) { if (e.code === 'ERR_INVALID_ARG_TYPE') { /* skip SNI, name missing */ } else throw e; }","preventionTips":["Pass servername in tls.connect options once instead of calling setServername later","Type-check values coming from config/env before reuse as hostnames"],"tags":["tls","sni","validation","type-error"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}