{"record":{"id":"ed2ef0d64a451d3c","repo":"denoland/deno","slug":"err-tls-required-server-name","errorCode":"ERR_TLS_REQUIRED_SERVER_NAME","errorMessage":"\"servername\" is required parameter for Server.addContext","messagePattern":"\"servername\" is required parameter for Server\\.addContext","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_tls_wrap.js","lineNumber":1501,"sourceCode":"    key: options.key,\n    maxVersion: options.maxVersion ?? defaults?.maxVersion,\n    minVersion: options.minVersion ?? defaults?.minVersion,\n    passphrase: options.passphrase,\n    pfx: options.pfx,\n    privateKeyEngine: options.privateKeyEngine,\n    privateKeyIdentifier: options.privateKeyIdentifier,\n    secureOptions: options.secureOptions,\n    secureProtocol: options.secureProtocol,\n    sessionIdContext: options.sessionIdContext,\n    sessionTimeout: options.sessionTimeout,\n    sigalgs: options.sigalgs,\n    ticketKeys: options.ticketKeys,\n  });\n};\n\nServer.prototype.addContext = function (servername, context) {\n  if (!servername) {\n    throw new ERR_TLS_REQUIRED_SERVER_NAME();\n  }\n  ArrayPrototypePush(this._contexts, [servername, context]);\n};\n\nServer.prototype.getTicketKeys = function getTicketKeys() {\n  return Buffer.from(this._ticketKeys);\n};\n\nServer.prototype.setTicketKeys = function setTicketKeys(keys) {\n  if (!isArrayBufferView(keys)) {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"keys\",\n      [\"Buffer\", \"TypedArray\", \"DataView\"],\n      keys,\n    );\n  }\n  if (getViewByteLength(keys) !== 48) {\n    throw new Error(\"Session ticket keys must be a 48-byte buffer\");","sourceCodeStart":1483,"sourceCodeEnd":1519,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_tls_wrap.js#L1483-L1519","documentation":"Server.prototype.addContext(servername, context) registers an SNI-specific SecureContext for the given hostname; servername is the routing key, so it must be truthy (ext/node/polyfills/_tls_wrap.js:1501). Passing '', null, or undefined throws ERR_TLS_REQUIRED_SERVER_NAME before the [servername, context] pair is pushed to this._contexts.","triggerScenarios":"server.addContext('', ctx) with an empty string; addContext(hostFromConfig) where the config entry lacked the host field (undefined); addContext(0) or other falsy coerced values.","commonSituations":"Looping over a certificate map (e.g. { 'example.com': { cert, key } }) and hitting an empty/missing key; loading vhost configs where one entry has no domain; refactoring code that previously passed the domain via a variable that is now unset.","solutions":["Check the domain is a non-empty string before registering: if (!servername) continue or throw a config error","Validate your certificate map entries at startup and report the offending entry instead of crashing inside addContext","Pass the plain hostname ('example.com'), not a URL or wildcard with protocol"],"exampleFix":"// before\nfor (const [domain, cfg] of Object.entries(certs)) {\n  server.addContext(domain, tls.createSecureContext(cfg)); // domain may be ''\n}\n\n// after\nfor (const [domain, cfg] of Object.entries(certs)) {\n  if (typeof domain !== 'string' || domain === '') continue;\n  server.addContext(domain, tls.createSecureContext(cfg));\n}","handlingStrategy":"validation","validationCode":"if (!servername || typeof servername !== 'string') throw new Error('addContext requires a non-empty servername');","typeGuard":"function isNonEmptyHost(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { server.addContext(servername, ctx); } catch (e) { if (e.code === 'ERR_TLS_REQUIRED_SERVER_NAME') { /* skip or log bad vhost entry */ } else throw e; }","preventionTips":["Validate certificate-map entries at startup and reject config with missing domains","Pass bare hostnames, not URLs"],"tags":["tls","sni","server","addcontext","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}