txthinking/brook · error
This is ipv4
Error message
This is ipv4
What it means
Resolve6 resolves a hostname/IP to an IPv6 address. Before doing anything it parses the input; if the input is already an IP with a non-nil To4() (an IPv4 or IPv4-mapped address), it refuses with "This is ipv4" because the AAAA lookup path only handles IPv6. Pure IPv6 literals are returned directly; hostnames go through a DNS AAAA query.
Source
Thrown at resolve.go:12
package brook
import (
"errors"
"net"
"github.com/miekg/dns"
)
func Resolve6(host string) (string, error) {
if net.ParseIP(host).To4() != nil {
return "", errors.New("This is ipv4")
}
if net.ParseIP(host).To16() != nil {
return host, nil
}
m := &dns.Msg{}
m.SetQuestion(host+".", dns.TypeAAAA)
r, err := dns.Exchange(m, "[2001:4860:4860::8888]:53")
if err != nil {
return "", err
}
for _, v := range r.Answer {
if t, ok := v.(*dns.AAAA); ok {
return t.AAAA.String(), nil
}
}
return "", errors.New("Can not find IP")
}
View on GitHub (pinned to 5cd13ef3b1)
Solutions
- Check the input with net.ParseIP before calling: if ip.To4() != nil use Resolve4 (or the IPv4 path) instead of Resolve6.
- If the goal is dual-stack resolution, call the generic resolver and let DNS pick A or AAAA records based on connectivity.
- Fix the configuration or environment so the host field for this code path is a hostname or IPv6 address only.
Example fix
// before
addr, err := Resolve6("8.8.8.8") // error: This is ipv4
// after
ip := net.ParseIP(host)
if ip != nil && ip.To4() != nil {
addr, err = Resolve4(host)
} else {
addr, err = Resolve6(host)
} Defensive patterns
Strategy: type-guard
Validate before calling
func isIPv4Literal(host string) bool {
ip := net.ParseIP(host)
return ip != nil && ip.To4() != nil
}
// call Resolve4 when isIPv4Literal(host), else Resolve6 Type guard
func isIPv6(host string) bool {
ip := net.ParseIP(host)
return ip != nil && ip.To4() == nil
} Try / catch
addr, err := Resolve6(host)
if err != nil && strings.Contains(err.Error(), "ipv4") {
addr, err = Resolve4(host)
} Prevention
- Parse and classify the host (To4/To16) before choosing Resolve4 vs Resolve6.
- Normalize IPv4-mapped literals (::ffff:x.x.x.x) to the IPv4 path.
- Prefer passing hostnames, not IP literals, to resolution helpers.
When it happens
Trigger: Calling Resolve6 with a dotted-quad IPv4 string like "8.8.8.8" or an IPv4-mapped form like "::ffff:8.8.8.8" — net.ParseIP succeeds and To4() is non-nil, so the function returns the error instead of resolving.
Common situations: Config files or URL hosts containing IPv4 addresses passed to an IPv6-only resolution path; code that assumed Resolve6 would fall back to IPv4; environment variables whose host field switches between IPv4 and IPv6 depending on deployment.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06).
Data as JSON: /api/errors/2348d081d19346cc.
Report an issue: GitHub.