lionsoul2014/ip2region · error
parse ip %s: %w
Error message
parse ip %s: %w
What it means
Go service Search: the string argument failed xdb.ParseIP, meaning it is neither a well-formed IPv4 nor IPv6 literal; the original input and parse error are both wrapped.
Source
Thrown at binding/golang/service/ip2region.go:128
v6Config = nil
} else {
v6Config, err = NewV6Config(VIndexCache, v6XdbPath, 20)
if err != nil {
return nil, fmt.Errorf("failed to create v6 config: %w", err)
}
}
return NewIp2Region(v4Config, v6Config)
}
func (ip2r *Ip2Region) Search(ip any) (string, error) {
var err error
var ipBytes []byte
switch v := ip.(type) {
case string:
ipBytes, err = xdb.ParseIP(v)
if err != nil {
return "", fmt.Errorf("parse ip %s: %w", v, err)
}
case []byte:
ipBytes = v
default:
return "", fmt.Errorf("invalid ip value type %s", v)
}
if l := len(ipBytes); l == 4 {
return ip2r.v4Search(ipBytes)
} else if l == 16 {
return ip2r.v6Search(ipBytes)
} else {
return "", fmt.Errorf("invalid byte ip address with len=%d", l)
}
}
func (ip2r *Ip2Region) v4Search(ipBytes []byte) (string, error) {
if ip2r.v4InMemSearcher != nil {View on GitHub (pinned to c1a1fc7d59)
Solutions
- Pass a valid IPv4/IPv6 string or pre-parsed 4/16-byte slice
- Resolve hostnames to IPs before calling Search
- Validate with net.ParseIP at the API boundary
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at binding/golang/service/ip2region.go:128 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/d25cb091b91afe79.
Report an issue: GitHub.