Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Length extends beyond buffer #39

Open
mauron85 opened this issue May 3, 2013 · 4 comments
Open

Length extends beyond buffer #39

mauron85 opened this issue May 3, 2013 · 4 comments

Comments

@mauron85
Copy link

mauron85 commented May 3, 2013

Hi, I'm storing results of Google Maps Places search and also Facebook Places into nStore.
But after some time I get following error:

version of nStore: 0.5.2

fs.js:457
  binding.read(fd, buffer, offset, length, position, wrapper);
          ^
Error: Length extends beyond buffer
    at Object.fs.read (fs.js:457:11)
    at readChunk (/private/var/www/myapp-nodejs/node_modules/nstore/lib/file.js:18:8)
    at fsRead (/private/var/www/myapp-nodejs/node_modules/nstore/lib/file.js:30:3)
    at checkQueue (/private/var/www/myapp-nodejs/node_modules/nstore/lib/file.js:63:5)
    at /private/var/www/myapp-nodejs/node_modules/nstore/lib/file.js:66:9
    at /private/var/www/myapp-nodejs/node_modules/nstore/lib/file.js:27:7
    at Object.wrapper [as oncomplete] (fs.js:454:17)
DEBUG: Program node server.js exited with code 8
@matthiasdg
Copy link

I had this problem as well. Did you edit your .db file manually? I noticed that this problem occurs if you have empty lines in the file; e.g. an empty line at the beginning, or you delete some entries manually and leave your cursor at the beginning of the last -now empty- line instead of at the end of the last populated line upon saving.

@mauron85
Copy link
Author

mauron85 commented May 6, 2013

No I didn't edit db file manually. I can replicate the issue with my this db:
https://dl.dropboxusercontent.com/u/150742/nStore-bug.zip

and followin testing code

var nStore = require('nstore');
nStore = nStore.extend(require('nstore/query')());
var provider = nStore.new('provider.db', function () {
  console.log('DB provider loaded');
  provider.all(function (err, results) {
    if (err) console.log(err);
    else {
      console.log(results);
      results.forEach(function(result) {
        console.log(result);
      });
    }
  });
});

@matthiasdg
Copy link

I took a quick look at your file and there is definitely something wrong with it; if you have an editor that shows line numbers, you'll see there is a line (25) starting with "photo" instead of a dbase key (after "were_here_count":3383 ). Normally, new lines start with a key.
If you delete that line completely (no idea what the missing part is; line 24 is complete, so it looks like there is quite a lot missing from 25), it works.

And in your test code, results is a single object (its keys are the dbase keys) so forEach won't work.

for(var key in results){
    console.log(results[key]);
}

So now your problem is reduced to finding out how your db file got corrupt :-)

@mauron85
Copy link
Author

mauron85 commented May 6, 2013

You're right. Right now i'm investigating what caused the wrong data was written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants