{"record":{"id":"d2310f1abf77c5e3","repo":"kovidgoyal/kitty","slug":"not-a-valid-ip-address-v-cannot-use-s","errorCode":null,"errorMessage":"Not a valid IP address: %#v. Cannot use: %s","messagePattern":"Not a valid IP address: %#v\\. Cannot use: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/utils/sockets.go","lineNumber":37,"sourceCode":"\t}\n\tif network == \"unix\" {\n\t\tif strings.HasPrefix(addr, \"@\") && runtime.GOOS != \"linux\" {\n\t\t\terr = fmt.Errorf(\"Abstract UNIX sockets are only supported on Linux. Cannot use: %s\", spec)\n\t\t}\n\t\treturn\n\t}\n\n\tif network == \"tcp\" || network == \"tcp6\" || network == \"tcp4\" {\n\t\thost := ipaddr.NewHostName(addr)\n\t\tif host.IsAddress() {\n\t\t\tnetwork = \"ip\"\n\t\t}\n\t\treturn\n\t}\n\tif network == \"ip\" || network == \"ip6\" || network == \"ip4\" {\n\t\thost := ipaddr.NewHostName(addr)\n\t\tif !host.IsAddress() {\n\t\t\terr = fmt.Errorf(\"Not a valid IP address: %#v. Cannot use: %s\", addr, spec)\n\t\t}\n\t\treturn\n\t}\n\tif network == \"fd\" {\n\t\tfd := -1\n\t\tif fd, err = strconv.Atoi(addr); err != nil || fd < 0 {\n\t\t\terr = fmt.Errorf(\"Not a valid file descriptor number: %#v. Cannot use: %s\", addr, spec)\n\t\t}\n\t\treturn\n\t}\n\terr = fmt.Errorf(\"Unknown network type: %#v in socket address: %s\", network, spec)\n\treturn\n}\n","sourceCodeStart":19,"sourceCodeEnd":51,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/utils/sockets.go#L19-L51","documentation":"For network types ip/ip4/ip6, ParseSocketAddress requires the address portion to parse as a bare IP address (validated via the ipaddress-go hostname parser's IsAddress). A hostname like 'localhost' or a malformed IP fails with this error.","triggerScenarios":"Specs like ip:localhost, ip:999.1.1.1, or ip6:127.0.0.1 (wrong family) — note ip4/ip6 family mismatches may pass this check but fail later at dial time; this error is specifically for non-IP-literal addresses.","commonSituations":"Confusing the ip (raw IP, no port) network with tcp (host:port); using DNS names where a literal IP is required; copy-pasted addresses with typos.","solutions":["Use a literal IP: ip:127.0.0.1 or ip6:::1.","Use tcp:hostname:port if you need DNS resolution and ports.","If only a hostname is known, resolve it with net.LookupHost before building the spec.","Fix typos in the IP literal."],"exampleFix":"// before\nnet, addr, err := utils.ParseSocketAddress(\"ip:localhost\")\n// after\nnet, addr, err := utils.ParseSocketAddress(\"tcp:localhost:8080\")","handlingStrategy":"validation","validationCode":"_, addr, _ := strings.Cut(spec, \":\")\nif net.ParseIP(addr) == nil {\n    return fmt.Errorf(\"%q is not an IP literal; use tcp: for hostnames\", addr)\n}","typeGuard":"func isIPLiteral(s string) bool {\n    return net.ParseIP(s) != nil\n}","tryCatchPattern":"net, addr, err := utils.ParseSocketAddress(spec)\nif err != nil && strings.Contains(err.Error(), \"Not a valid IP address\") {\n    ips, _ := net.LookupHost(hostname)\n    net, addr, err = utils.ParseSocketAddress(\"ip:\" + ips[0])\n}","preventionTips":["Use tcp:host:port when DNS names or ports are needed.","Resolve hostnames to literals before building ip: specs.","Pick ip4/ip6 matching the literal's actual family."],"tags":["go","sockets","ip-address","validation"],"backgroundTag":"invalid-socket-address","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}