{"record":{"id":"e14c41d2860f0e7a","repo":"lionsoul2014/ip2region","slug":"invalid-byte-ip-address-with-len-d","errorCode":null,"errorMessage":"invalid byte ip address with len=%d","messagePattern":"invalid byte ip address with len=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/service/ip2region.go","lineNumber":141,"sourceCode":"\tvar ipBytes []byte\n\tswitch v := ip.(type) {\n\tcase string:\n\t\tipBytes, err = xdb.ParseIP(v)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"parse ip %s: %w\", v, err)\n\t\t}\n\tcase []byte:\n\t\tipBytes = v\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid ip value type %s\", v)\n\t}\n\n\tif l := len(ipBytes); l == 4 {\n\t\treturn ip2r.v4Search(ipBytes)\n\t} else if l == 16 {\n\t\treturn ip2r.v6Search(ipBytes)\n\t} else {\n\t\treturn \"\", fmt.Errorf(\"invalid byte ip address with len=%d\", l)\n\t}\n}\n\nfunc (ip2r *Ip2Region) v4Search(ipBytes []byte) (string, error) {\n\tif ip2r.v4InMemSearcher != nil {\n\t\treturn ip2r.v4InMemSearcher.Search(ipBytes)\n\t}\n\n\t// v4 search is disabled\n\tif ip2r.v4Pool == nil {\n\t\treturn \"\", nil\n\t}\n\n\tv4Searcher := ip2r.v4Pool.BorrowSearcher()\n\tif v4Searcher == nil {\n\t\treturn \"\", fmt.Errorf(\"v4 searcher pool already closed\")\n\t}\n\tdefer ip2r.v4Pool.ReturnSearcher(v4Searcher)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/service/ip2region.go#L123-L159","documentation":"Go service Search: the supplied []byte IP is neither 4 bytes (IPv4) nor 16 bytes (IPv6), so its family cannot be routed to a searcher; the length is echoed in the message.","triggerScenarios":"Thrown at binding/golang/service/ip2region.go:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass exactly 4 bytes for IPv4 or 16 bytes for IPv6","Use net.IP.To4()/To16() to normalize byte slices before searching","Validate len(ip) at the call site"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}