{"record":{"id":"3419c35d494e25ef","repo":"lionsoul2014/ip2region","slug":"invalid-ip-address-iptostring-ipbytes-thi","errorCode":null,"errorMessage":"invalid ip address '${ipToString(ipBytes)}' (${this.version.name} expected)","messagePattern":"invalid ip address '(.+?)' \\((.+?) expected\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"binding/javascript/searcher.js","lineNumber":45,"sourceCode":"            this.cBuffer = null;\n        }\n    }\n\n    getIPVersion() {\n        return this.version;\n    }\n\n    getIOCount() {\n        return this.ioCount;\n    }\n\n    async search(ip) {\n        // check and parse the string ip\n        const ipBytes = Buffer.isBuffer(ip) ? ip : parseIP(ip);\n\n        // ip version check\n        if (ipBytes.length != this.version.bytes) {\n            throw new Error(`invalid ip address '${ipToString(ipBytes)}' (${this.version.name} expected)`);\n        }\n\n        // reset the global counter\n        this.ioCount = 0;\n\n        // located the segment index block based on the vector index\n        let sPtr = 0, ePtr = 0;\n        let il0 = ipBytes[0], il1 = ipBytes[1];\n        let idx = il0 * VectorIndexCols * VectorIndexSize + il1 * VectorIndexSize;\n        if (this.vectorIndex != null) {\n            sPtr = this.vectorIndex.readUint32LE(idx);\n            ePtr = this.vectorIndex.readUint32LE(idx + 4);\n        } else if (this.cBuffer != null) {\n            sPtr = this.cBuffer.readUint32LE(HeaderInfoLength + idx);\n            ePtr = this.cBuffer.readUint32LE(HeaderInfoLength + idx + 4);\n        } else {\n            const buff = Buffer.alloc(VectorIndexSize);\n            this.read(HeaderInfoLength + idx, buff);","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/javascript/searcher.js#L27-L63","documentation":"Thrown by the JS searcher when the parsed IP's byte length (4 for IPv4, 16 for IPv6) does not match the byte width of this searcher's version, e.g. feeding an IPv6 string to a searcher opened on an IPv4 xdb. It is a version-consistency guard fired after parseIP succeeds, not a syntax error.","triggerScenarios":"Thrown at binding/javascript/searcher.js:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Instantiate the searcher with the xdb file matching the IP family being queried (v4 xdb for 4-byte IPs, v6 xdb for 16-byte IPs)","Check searcher.getIPVersion() before calling search and route the query to the right searcher","Auto-detect the family from the string (presence of ':') and pick the corresponding searcher"],"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"}