{"record":{"id":"d7fedd2264925989","repo":"vitessio/vitess","slug":"splithostport-missing-port-in-q","errorCode":null,"errorMessage":"SplitHostPort: missing port in %q","messagePattern":"SplitHostPort: missing port in %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/netutil/netutil.go","lineNumber":39,"sourceCode":"\t\"bytes\"\n\t\"fmt\"\n\t\"net\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// SplitHostPort is an alternative to net.SplitHostPort that also parses the\n// integer port. In addition, it is more tolerant of improperly escaped IPv6\n// addresses, such as \"::1:456\", which should actually be \"[::1]:456\".\nfunc SplitHostPort(addr string) (string, int, error) {\n\thost, port, err := net.SplitHostPort(addr)\n\tif err != nil {\n\t\t// If the above proper parsing fails, fall back on a naive split.\n\t\ti := strings.LastIndex(addr, \":\")\n\t\tif i < 0 {\n\t\t\treturn \"\", 0, fmt.Errorf(\"SplitHostPort: missing port in %q\", addr)\n\t\t}\n\t\thost = addr[:i]\n\t\tport = addr[i+1:]\n\t}\n\tp, err := strconv.ParseUint(port, 10, 16)\n\tif err != nil {\n\t\treturn \"\", 0, fmt.Errorf(\"SplitHostPort: can't parse port %q: %v\", port, err)\n\t}\n\treturn host, int(p), nil\n}\n\n// JoinHostPort is an extension to net.JoinHostPort that also formats the\n// integer port.\nfunc JoinHostPort(host string, port int32) string {\n\treturn net.JoinHostPort(host, strconv.FormatInt(int64(port), 10))\n}\n\n// FullyQualifiedHostname returns the FQDN of the machine.","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/netutil/netutil.go#L21-L57","documentation":"SplitHostPort wraps net.SplitHostPort with a naive fallback split. This error is returned when the address contains no ':' at all, so neither proper nor naive parsing can find a port. It indicates the caller passed a bare hostname/IP without a port component.","triggerScenarios":"Calling netutil.SplitHostPort (directly or via Connect, FindReplicas) with an address like \"localhost\" or \"10.0.0.1\" that has no \":port\" suffix.","commonSituations":"Config files or command-line flags where the port was omitted (e.g. vtctld or tablet address configured as host only); template-generated addresses where the port field was empty; users forgetting the port when entering replica addresses.","solutions":["Append the port to the address, e.g. \"localhost:15002\" instead of \"localhost\"","Fix the config flag/env var that supplies the address so it always includes the port","Use netutil.JoinHostPort(host, port) when constructing addresses programmatically","Validate the address contains a colon before calling SplitHostPort"],"exampleFix":"// before\nhost, port, err := netutil.SplitHostPort(\"localhost\")\n// after\nhost, port, err := netutil.SplitHostPort(\"localhost:15002\")","handlingStrategy":"validation","validationCode":"func validateAddr(addr string) error {\n    if !strings.Contains(addr, \":\") {\n        return fmt.Errorf(\"address %q must include a port (host:port)\", addr)\n    }\n    return nil\n}\nvalidateAddr(addr) // call before netutil.SplitHostPort","typeGuard":null,"tryCatchPattern":"host, port, err := netutil.SplitHostPort(addr)\nif err != nil {\n    return fmt.Errorf(\"invalid address %q: %w\", addr, err)\n}","preventionTips":["Always build addresses with netutil.JoinHostPort(host, port)","Validate flags/config containing addresses at startup (PreRunE)","Include port in all tablet/replica address configuration"],"tags":["network","address-parsing","missing-port"],"backgroundTag":"missing-port-in-address","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}