lionsoul2014/ip2region · error
invalid version name `%s`
Error message
invalid version name `%s`
What it means
VersionFromName maps textual version names ('V4', 'IPV4', 'V6', 'IPV6', case-insensitive) to the Version enum. Any other string hits the default branch and yields 'invalid version name'. It is a strict input-validation error used by CLI commands like Bench, Edit, and Generate.
Source
Thrown at binding/golang/xdb/version.go:88
if err != nil {
return IPvx, fmt.Errorf("parse ip fail: %w", err)
}
if len(r) == 4 {
return IPv4, nil
}
return IPv6, nil
}
func VersionFromName(name string) (*Version, error) {
switch strings.ToUpper(name) {
case "V4", "IPV4":
return IPv4, nil
case "V6", "IPV6":
return IPv6, nil
default:
return IPvx, fmt.Errorf("invalid version name `%s`", name)
}
}
func VersionFromHeader(header *Header) (*Version, error) {
// old structure with IPv4 supports ONLY
if header.Version == Structure20 {
return IPv4, nil
}
// structure 3.0 after IPv6 supporting
if header.Version != Structure30 {
return IPvx, fmt.Errorf("invalid version `%d`", header.Version)
}
switch header.IPVersion {
case IPv4VersionNo:
return IPv4, nil
case IPv6VersionNo:View on GitHub (pinned to c1a1fc7d59)
Solutions
- Pass one of the accepted names: v4, ipv4, v6, ipv6 (case-insensitive)
- Trim whitespace and normalize case before calling VersionFromName
- Derive the name programmatically from the xdb header via VersionFromHeader instead of hardcoding a string
- Map legacy config values (e.g. '4'/'6') to 'v4'/'v6' before invoking
Example fix
// before
v, err := xdb.VersionFromName(cfg.IPVer) // cfg.IPVer == "4" -> invalid
// after
name := map[string]string{"4": "v4", "6": "v6"}[strings.TrimSpace(cfg.IPVer)]
if name == "" { name = cfg.IPVer }
v, err := xdb.VersionFromName(name) Defensive patterns
Strategy: validation
Validate before calling
func knownVersionName(name string) bool {
switch strings.ToUpper(strings.TrimSpace(name)) {
case "V4", "IPV4", "V6", "IPV6": return true
}
return false
} Type guard
func isVersionName(s string) bool { _, err := xdb.VersionFromName(s); return err == nil } Try / catch
v, err := xdb.VersionFromName(name)
if err != nil { return fmt.Errorf("--version must be v4|ipv4|v6|ipv6, got %q", name) } Prevention
- Normalize and trim CLI/config input before mapping to Version
- Derive the version from the xdb header instead of user text where possible
- Document accepted names where the flag is exposed
- Add table tests covering all accepted spellings
When it happens
Trigger: Passing a name such as 'ipv 4', '4', 'v.4', an empty string, or a localized label to VersionFromName or the --version flag of the Bench/Edit/Generate CLI tools.
Common situations: Scripting the CLI with a variable that is empty, using 'IPv4' with stray whitespace, or confusing the version name with a structure version (e.g. '3.0').
Related errors
- parse ip fail: %w
- invalid version `%d`
- invalid structure version {}
- invalid ip address: %s
- length of the two ips are not the same
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/968cfb3afe8792aa.
Report an issue: GitHub.