denoland/deno · error · Error
ERR_TLS_REQUIRED_SERVER_NAME
ERR_TLS_REQUIRED_SERVER_NAME
Error message
"servername" is required parameter for Server.addContext
What it means
tls.Server.prototype.addContext(servername, context) registers a SecureContext for SNI routing on the server. The polyfill requires a truthy servername; empty string, null, undefined, 0, and false all throw ERR_TLS_REQUIRED_SERVER_NAME before the [servername, context] pair is pushed onto the server's context list.
Solutions
- Always pass a non-empty hostname string first: server.addContext('example.com', ctx)
- Skip empty keys when registering from maps: if (!host) continue;
- For dynamic SNI prefer SNICallback, which can fall back to a default context for unknown names
Example fix
// before
for (const [host, ctx] of Object.entries(certs)) {
server.addContext(host, ctx); // throws when host === ''
}
// after
for (const [host, ctx] of Object.entries(certs)) {
if (host) server.addContext(host, ctx);
} Defensive patterns
Strategy: validation
Validate before calling
for (const [host, ctx] of Object.entries(certMap)) {
if (typeof host === 'string' && host.length > 0) {
server.addContext(host, ctx);
}
} Type guard
function isNonEmptyServername(v: unknown): v is string {
return typeof v === 'string' && v.length > 0;
} Try / catch
try {
server.addContext(servername, ctx);
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ERR_TLS_REQUIRED_SERVER_NAME') {
// skip or log the empty-hostname entry and continue the registration loop
} else throw err;
} Prevention
- Filter empty/missing hostname keys before registering SNI contexts
- Remember the argument order: (servername, context)
- Prefer SNICallback with a default context for dynamic setups
When it happens
Trigger: server.addContext('', ctx), server.addContext(undefined, ctx), or addContext(ctx, 'example.com') with the argument order swapped so servername is a truthy-but-wrong object while the real name lands in context.
Common situations: Looping over a hostname→cert map where one key is empty; SNI registration driven by request Host headers or user input that can be blank; forgetting the parameter order.
Understand the failure class
- SSL/TLS and certificate errors — how TLS handshakes and certificate validation fail.
Related errors
- ERR_INVALID_ARG_TYPE
- ERR_INVALID_ARG_VALUE
- ERR_TLS_SNI_FROM_SERVER
- Session ticket keys must be a 48-byte buffer
- ERR_INVALID_ARG_TYPE
AI-assisted analysis of denoland/deno@f7822238ca (2026-08-20).
Data as JSON: /api/errors/ed2ef0d64a451d3c.
Report an issue: GitHub.
Appendix: source
Thrown at ext/node/polyfills/_tls_wrap.js:1516
key: options.key,
maxVersion: options.maxVersion ?? defaults?.maxVersion,
minVersion: options.minVersion ?? defaults?.minVersion,
passphrase: options.passphrase,
pfx: options.pfx,
privateKeyEngine: options.privateKeyEngine,
privateKeyIdentifier: options.privateKeyIdentifier,
secureOptions: options.secureOptions,
secureProtocol: options.secureProtocol,
sessionIdContext: options.sessionIdContext,
sessionTimeout: options.sessionTimeout,
sigalgs: options.sigalgs,
ticketKeys: options.ticketKeys,
});
};
Server.prototype.addContext = function (servername, context) {
if (!servername) {
throw new ERR_TLS_REQUIRED_SERVER_NAME();
}
ArrayPrototypePush(this._contexts, [servername, context]);
};
Server.prototype.getTicketKeys = function getTicketKeys() {
return Buffer.from(this._ticketKeys);
};
Server.prototype.setTicketKeys = function setTicketKeys(keys) {
if (!isArrayBufferView(keys)) {
throw new ERR_INVALID_ARG_TYPE(
"keys",
["Buffer", "TypedArray", "DataView"],
keys,
);
}
if (getViewByteLength(keys) !== 48) {
throw new Error("Session ticket keys must be a 48-byte buffer");View on GitHub (pinned to f7822238ca)