{"record":{"id":"68f0c95a28d9d6b3","repo":"lionsoul2014/ip2region","slug":"invalid-version-d-68f0c9","errorCode":null,"errorMessage":"invalid version `%d`","messagePattern":"invalid version `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/xdb/version.go","lineNumber":100,"sourceCode":"\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:\n\t\treturn IPv6, nil\n\tdefault:\n\t\treturn IPvx, fmt.Errorf(\"invalid version `%d`\", header.IPVersion)\n\t}\n}\n","sourceCodeStart":82,"sourceCodeEnd":112,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/xdb/version.go#L82-L112","documentation":"VersionFromHeader inspects the xdb file header to decide the IP version. Old (2.0) structures are IPv4-only; new (3.0) headers carry an explicit IP version. If header.Version is neither Structure20 nor Structure30, the header is corrupt or from an unknown format and this error is thrown with the raw version number.","triggerScenarios":"Calling VersionFromHeader (directly or via NewSearcher/newConfig) on a file whose 256-byte header was truncated, corrupted in transfer, or written by an unrecognized writer version; or pointing the searcher at a non-xdb file.","commonSituations":"Partial uploads/FTP transfers in ASCII mode corrupting the header, downloading an HTML error page saved as .xdb, opening an unrelated binary renamed to .xdb, or a file produced by a newer incompatibly-versioned maker.","solutions":["Re-download/re-export the xdb file and verify its size and checksum against the publisher","Verify the file starts with a valid xdb header (check the first bytes / try Header verification tooling)","Ensure the file was generated with a compatible maker version (structure 2.0 or 3.0)","Confirm the path points to the xdb data file, not an index or config file"],"exampleFix":"// before\nv, err := xdb.VersionFromHeader(hdr) // hdr.Version == 0 (truncated file)\n// after\nfi, _ := os.Stat(xdbPath)\nif fi == nil || fi.Size() < 256 { return fmt.Errorf(\"xdb too small/corrupt: %s\", xdbPath) }\nv, err := xdb.VersionFromHeader(hdr)","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(xdbPath)\nif err != nil || fi.Size() < 256 { return fmt.Errorf(\"xdb missing or truncated: %s\", xdbPath) }","typeGuard":"func looksLikeXDB(b []byte) bool { return len(b) >= 256 }\n// then: v, err := xdb.VersionFromHeader(hdr); usable if err == nil","tryCatchPattern":"hdr, err := xdb.LoadHeaderFromFile(xdbPath)\nif err != nil { return fmt.Errorf(\"cannot read xdb header %s: %w\", xdbPath, err) }\nv, err := xdb.VersionFromHeader(hdr)\nif err != nil { return fmt.Errorf(\"unsupported xdb %s: %w\", xdbPath, err) }","preventionTips":["Verify checksums/sizes after downloading xdb files","Never rename unrelated binaries to .xdb","Pin maker tool versions compatible with structure 2.0/3.0","Fail fast at startup by loading the header once"],"tags":["go","xdb-header","corrupt-file","version"],"backgroundTag":"invalid-xdb-header-version","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}