{"record":{"id":"514f1d4ca6aec9af","repo":"txthinking/brook","slug":"can-not-find-ip","errorCode":null,"errorMessage":"Can not find IP","messagePattern":"Can not find IP","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"resolve.go","lineNumber":28,"sourceCode":"func Resolve6(host string) (string, error) {\n\tif net.ParseIP(host).To4() != nil {\n\t\treturn \"\", errors.New(\"This is ipv4\")\n\t}\n\tif net.ParseIP(host).To16() != nil {\n\t\treturn host, nil\n\t}\n\tm := &dns.Msg{}\n\tm.SetQuestion(host+\".\", dns.TypeAAAA)\n\tr, err := dns.Exchange(m, \"[2001:4860:4860::8888]:53\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tfor _, v := range r.Answer {\n\t\tif t, ok := v.(*dns.AAAA); ok {\n\t\t\treturn t.AAAA.String(), nil\n\t\t}\n\t}\n\treturn \"\", errors.New(\"Can not find IP\")\n}\n\nfunc Resolve4(host string) (string, error) {\n\tif net.ParseIP(host).To4() != nil {\n\t\treturn host, nil\n\t}\n\tif net.ParseIP(host).To16() != nil {\n\t\treturn \"\", errors.New(\"This is ipv6\")\n\t}\n\tm := &dns.Msg{}\n\tm.SetQuestion(host+\".\", dns.TypeA)\n\tr, err := dns.Exchange(m, \"8.8.8.8:53\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tfor _, v := range r.Answer {\n\t\tif t, ok := v.(*dns.A); ok {\n\t\t\treturn t.A.String(), nil","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/resolve.go#L10-L46","documentation":"Resolve6 performs a DNS AAAA lookup (after first passing through any literal IPv6 address). This error is returned when the DNS exchange succeeded (no transport error) but the answer section contained no AAAA record — i.e. the host genuinely has no IPv6 address, or the record type in the response was unexpected.","triggerScenarios":"Calling Resolve6(host) where the DNS query to 8.8.8.8:53 returns answers but none is a *dns.AAAA record: host has only A records, NXDOMAIN/NODATA responses with empty Answer, or CNAME-only chains without a terminal AAAA.","commonSituations":"Looking up IPv6 for IPv4-only hosts (many services and most home networks are v4-only); querying a hostname on a DNS server that lacks AAAA records; typos in the hostname producing empty answer sections.","solutions":["Verify the host actually has an IPv6 record: dig AAAA <host> @8.8.8.8; if absent, fall back to Resolve4.","Call Resolve6 and treat the error as 'no IPv6 available' — fall back to Resolve4(host) on error.","If you passed a literal IP, confirm it is IPv6 (Resolve6 handles literals only if it checks ParseIP before; pass the address in standard form).","Check network reachability to 8.8.8.8:53 (UDP 53 egress allowed) so a silent/empty response is not misread."],"exampleFix":"// before\nip, err := Resolve6(host)\nif err != nil { return err }\n// after\nip, err := Resolve6(host)\nif err != nil {\n    // no AAAA record — fall back to IPv4\n    return Resolve4(host)\n}","handlingStrategy":"fallback","validationCode":"if net.ParseIP(host) == nil {\n    // optional pre-check: does the host plausibly have AAAA?\n    // dig AAAA <host> can be run out-of-band\n}","typeGuard":"func isIPv6Literal(s string) bool {\n    ip := net.ParseIP(s)\n    return ip != nil && ip.To4() == nil\n}","tryCatchPattern":"ip, err := Resolve6(host)\nif err != nil {\n    ip, err = Resolve4(host)\n    if err != nil { return fmt.Errorf(\"no address for %q: %w\", host, err) }\n}","preventionTips":["Always provide an IPv4 fallback path when resolving hostnames.","Check AAAA availability with dig before relying on IPv6 connectivity.","Never assume every hostname is dual-stack."],"tags":["dns","ipv6","resolution-failed","network"],"backgroundTag":"empty-result-set","analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}