{"record":{"id":"f572e44cacb1e932","repo":"lionsoul2014/ip2region","slug":"incomplete-read-read-bytes-should-be-buff-lengt","errorCode":null,"errorMessage":"incomplete read: read bytes should be ${buff.length}","messagePattern":"incomplete read: read bytes should be (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"binding/javascript/searcher.js","lineNumber":122,"sourceCode":"        const region = Buffer.alloc(dLen);\n        this.read(dPtr, region);\n        return region.toString('utf-8');\n    }\n\n    read(offset, buff, stats) {\n        // check the in-memory buffer first\n        if (this.cBuffer != null) {\n            this.cBuffer.copy(buff, 0, offset, offset + buff.length);\n            return;\n        }\n\n        // increase the io counts\n        this.ioCount++;\n        \n        // read the data\n        let rBytes = fs.readSync(this.handle, buff, 0, buff.length, offset);\n        if (rBytes != buff.length) {\n            throw new Error(`incomplete read: read bytes should be ${buff.length}`);\n        }\n    }\n\n    // close the searcher\n    close() {\n        if (this.handle != null) {\n            fs.close(this.handle);\n        }\n    }\n\n    toString() {\n        const vn = this.version.name;\n        const vi = this.vectorIndex == null ? 'null' : this.vectorIndex.length;\n        const cf = this.cBuffer == null ? 'null' : this.cBuffer.length;\n        return `{\"version\": ${vn}, \"dbPath\": ${this.dbPath}, \"handle\": ${this.handle}, \"vectorIndex\": ${vi} \"cBuffer\": ${cf}}`;\n    }\n}\n","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/javascript/searcher.js#L104-L140","documentation":"A sentinel I/O integrity error raised in the JS searcher's read() when fs.readSync returns fewer bytes than the requested buffer length while loading a header, vector-index row, segment index, or region data from the xdb file. It almost always means the file was truncated, corrupted, or concurrently replaced after the searcher was opened.","triggerScenarios":"Thrown at binding/javascript/searcher.js:122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the xdb file integrity (re-download or re-generate it with the maker) and compare its size against the header's end pointer","Reopen the searcher on a known-good xdb file; do not keep a handle to a file that can be swapped underneath","If loading the whole file, prefer the content-buffer constructor so partial reads from a shrinking file cannot occur mid-search"],"exampleFix":null,"handlingStrategy":"try-catch","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"}