{"record":{"id":"a271a31adfe455fa","repo":"mongodb/node-mongodb-native","slug":"serverdescription-must-be-provided-with-a-non-empt","errorCode":null,"errorMessage":"ServerDescription must be provided with a non-empty address","messagePattern":"ServerDescription must be provided with a non-empty address","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/sdam/server_description.ts","lineNumber":103,"sourceCode":"  iscryptd: boolean;\n\n  // NOTE: does this belong here? It seems we should gossip the cluster time at the CMAP level\n  $clusterTime?: ClusterTime;\n\n  /**\n   * Create a ServerDescription\n   * @internal\n   *\n   * @param address - The address of the server\n   * @param hello - An optional hello response for this server\n   */\n  constructor(\n    address: HostAddress | string,\n    hello?: Document,\n    options: ServerDescriptionOptions = {}\n  ) {\n    if (address == null || address === '') {\n      throw new MongoRuntimeError('ServerDescription must be provided with a non-empty address');\n    }\n\n    this.address =\n      typeof address === 'string'\n        ? HostAddress.fromString(address).toString() // Use HostAddress to normalize\n        : address.toString();\n    this.type = parseServerType(hello, options);\n    this.hosts = hello?.hosts?.map((host: string) => host.toLowerCase()) ?? [];\n    this.passives = hello?.passives?.map((host: string) => host.toLowerCase()) ?? [];\n    this.arbiters = hello?.arbiters?.map((host: string) => host.toLowerCase()) ?? [];\n    this.tags = hello?.tags ?? {};\n    this.minWireVersion = hello?.minWireVersion ?? 0;\n    this.maxWireVersion = hello?.maxWireVersion ?? 0;\n    this.roundTripTime = options?.roundTripTime ?? -1;\n    this.minRoundTripTime = options?.minRoundTripTime ?? 0;\n    this.lastUpdateTime = processTimeMS();\n    this.lastWriteDate = hello?.lastWrite?.lastWriteDate ?? 0;\n    // NOTE: This actually builds the stack string instead of holding onto the getter and all its","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/sdam/server_description.ts#L85-L121","documentation":"Thrown by the ServerDescription constructor (src/sdam/server_description.ts:103) as MongoRuntimeError when the address argument is null, undefined, or the empty string. ServerDescription is an internal type representing a server's address and hello metadata; it always requires a host:port. This error usually signals a malformed seed in the connection string or an internal topology misconfiguration.","triggerScenarios":"A connection string with an empty host segment (e.g. mongodb:///dbname or mongodb://:27017), or internal topology code constructing a ServerDescription with an undefined address.","commonSituations":"Malformed URI in configuration/env vars, dynamic URI construction that drops the host, or a bug in seedlist parsing.","solutions":["Validate the connection string has a non-empty host before connecting.","Log the constructed URI at startup to catch empty-host mistakes.","If seen from internal code paths, report to driver maintainers."],"exampleFix":"// before\nconst client = new MongoClient('mongodb:///test');\n// after\nconst client = new MongoClient('mongodb://localhost:27017/test');","handlingStrategy":"validation","validationCode":"function assertValidUri(uri) {\n  const parsed = new URL(uri);\n  if (!parsed.hostname && !parsed.host) throw new Error('connection string missing host');\n}","typeGuard":"function isNonEmptyAddress(v): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoRuntimeError && /non-empty address/.test(e.message)) {\n    // fix the connection string\n  }\n  throw e;\n}","preventionTips":["Validate connection strings have a host before constructing MongoClient.","Log the final URI used at startup.","Avoid dynamically building URIs that can drop the host segment."],"tags":["sdam","connection-string","validation","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}