{"record":{"id":"968cfb3afe8792aa","repo":"lionsoul2014/ip2region","slug":"invalid-version-name-s","errorCode":null,"errorMessage":"invalid version name `%s`","messagePattern":"invalid version name `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/xdb/version.go","lineNumber":88,"sourceCode":"\tif err != nil {\n\t\treturn IPvx, fmt.Errorf(\"parse ip fail: %w\", err)\n\t}\n\n\tif len(r) == 4 {\n\t\treturn IPv4, nil\n\t}\n\n\treturn IPv6, nil\n}\n\nfunc VersionFromName(name string) (*Version, error) {\n\tswitch strings.ToUpper(name) {\n\tcase \"V4\", \"IPV4\":\n\t\treturn IPv4, nil\n\tcase \"V6\", \"IPV6\":\n\t\treturn IPv6, nil\n\tdefault:\n\t\treturn IPvx, fmt.Errorf(\"invalid version name `%s`\", name)\n\t}\n}\n\nfunc VersionFromHeader(header *Header) (*Version, error) {\n\t// old structure with IPv4 supports ONLY\n\tif header.Version == Structure20 {\n\t\treturn IPv4, nil\n\t}\n\n\t// structure 3.0 after IPv6 supporting\n\tif header.Version != Structure30 {\n\t\treturn IPvx, fmt.Errorf(\"invalid version `%d`\", header.Version)\n\t}\n\n\tswitch header.IPVersion {\n\tcase IPv4VersionNo:\n\t\treturn IPv4, nil\n\tcase IPv6VersionNo:","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/xdb/version.go#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","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"],"exampleFix":"// before\nv, err := xdb.VersionFromName(cfg.IPVer) // cfg.IPVer == \"4\" -> invalid\n// after\nname := map[string]string{\"4\": \"v4\", \"6\": \"v6\"}[strings.TrimSpace(cfg.IPVer)]\nif name == \"\" { name = cfg.IPVer }\nv, err := xdb.VersionFromName(name)","handlingStrategy":"validation","validationCode":"func knownVersionName(name string) bool {\n    switch strings.ToUpper(strings.TrimSpace(name)) {\n    case \"V4\", \"IPV4\", \"V6\", \"IPV6\": return true\n    }\n    return false\n}","typeGuard":"func isVersionName(s string) bool { _, err := xdb.VersionFromName(s); return err == nil }","tryCatchPattern":"v, err := xdb.VersionFromName(name)\nif err != nil { return fmt.Errorf(\"--version must be v4|ipv4|v6|ipv6, got %q\", name) }","preventionTips":["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"],"tags":["go","validation","cli","version"],"backgroundTag":"invalid-version-name","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}