{"record":{"id":"7787a76dc95d8eab","repo":"nats-io/nats-server","slug":"no-hostport-specified","errorCode":null,"errorMessage":"no hostport specified","messagePattern":"no hostport specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/util.go","lineNumber":174,"sourceCode":"\tif hostPort != \"\" {\n\t\thost, sPort, err := net.SplitHostPort(hostPort)\n\t\tif ae, ok := err.(*net.AddrError); ok && strings.Contains(ae.Err, \"missing port\") {\n\t\t\t// try appending the current port\n\t\t\thost, sPort, err = net.SplitHostPort(fmt.Sprintf(\"%s:%d\", hostPort, defaultPort))\n\t\t}\n\t\tif err != nil {\n\t\t\treturn \"\", -1, err\n\t\t}\n\t\tport, err = strconv.Atoi(strings.TrimSpace(sPort))\n\t\tif err != nil {\n\t\t\treturn \"\", -1, err\n\t\t}\n\t\tif port == 0 || port == -1 {\n\t\t\tport = defaultPort\n\t\t}\n\t\treturn strings.TrimSpace(host), port, nil\n\t}\n\treturn \"\", -1, errors.New(\"no hostport specified\")\n}\n\n// Returns true if URL u1 represents the same URL than u2,\n// false otherwise.\nfunc urlsAreEqual(u1, u2 *url.URL) bool {\n\treturn reflect.DeepEqual(u1, u2)\n}\n\n// comma produces a string form of the given number in base 10 with\n// commas after every three orders of magnitude.\n//\n// e.g. comma(834142) -> 834,142\n//\n// This function was copied from the github.com/dustin/go-humanize\n// package (MIT License) and is Copyright Dustin Sallings <dustin@spy.net>\nfunc comma(v int64) string {\n\tsign := \"\"\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/util.go#L156-L192","documentation":"parseHostPort in server/util.go validates and splits a \"host:port\" string. When it receives an empty or missing hostport value it returns the sentinel error \"no hostport specified\" with port -1. The library treats this as a configuration error because callers cannot form a valid listen/advertise address without it.","triggerScenarios":"Calling setGatewayInfoHostPort, setLeafNodeInfoHostPortAndIP, setRouteInfoHostPortAndIP, setInfoHostPort, diffOptions or validateClusterOpts with an empty string or a value without a host part (e.g. `\":4222\"`-style values missing entirely, or an empty option) — the underlying host portion is blank so parseHostPort bails out before defaulting the port.","commonSituations":"NATS server config with an empty `host`/`listen` value in gateway, leafnode, cluster or route blocks; environment-variable interpolation producing an empty string; programmatic option construction (server.Options) leaving Host empty while a port-only URL was expected to include a host.","solutions":["Set a valid host value in the relevant config block (e.g. host: \"0.0.0.0\" or the advertised hostname) instead of leaving it empty","Check environment variables or templates that substitute the host — an unset variable yields an empty hostport","If building Options in code, ensure options.Host (or the block's Host field) is non-empty before calling server.New/Parse","For cluster/route URLs, use full `host:port` URLs such as nats-route://host:4222"],"exampleFix":"// before (server.conf)\ncluster {\n  name: c1\n  host: \"\"\n  port: 4222\n}\n// after\ncluster {\n  name: c1\n  host: \"0.0.0.0\"\n  port: 4222\n}","handlingStrategy":"validation","validationCode":"func validateHostPort(hp string) error {\n    if strings.TrimSpace(hp) == \"\" {\n        return errors.New(\"hostport must be non-empty, e.g. 0.0.0.0:4222\")\n    }\n    if _, _, err := net.SplitHostPort(hp); err != nil {\n        return fmt.Errorf(\"invalid hostport %q: %w\", hp, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never leave host fields empty in gateway/leafnodes/cluster blocks","Use absolute hostnames or 0.0.0.0 explicitly in configs","Guard env substitutions with defaults: ${HOST:-0.0.0.0}","Run nats-server -t to validate options before start"],"tags":["config","hostport","nats-server","startup"],"backgroundTag":"missing-host-port-config","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}