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

Inserting multiple items with the same _id into a local collection results in very confusing error #1246

Closed
mizzao opened this Issue Jul 25, 2013 · 8 comments

Comments

Projects
None yet
3 participants
@mizzao
Contributor

mizzao commented Jul 25, 2013

Both myself and at least one other user have seen the following very strange bug pop up spontaneously in a Meteor app:

Exception from sub undefined Error
    at app/packages/minimongo/minimongo.js:50:44
    at /tmp/meteor-test-run4k7izj/.meteor/local/build/server/server.js:298:12
    at Array.forEach (native)
    at Function._.each._.forEach (/home/mao/.meteor/tools/d699ad29da/lib/node_modules/underscore/underscore.js:78:11)
    at run (/tmp/meteor-test-run4k7izj/.meteor/local/build/server/server.js:239:7)

It doesn't tell you what exactly the problem is (why is minimongo on the server anyway?) and I could only get it to go away by randomly changing my code around.

References:

  1. https://groups.google.com/forum/#!topic/meteor-talk/r6ENlLsrxoY
  2. http://stackoverflow.com/q/17865319/586086

As you can see, it's not related to the fact that I was using Tinytest as another user has also had the same problem during normal Meteor use.

I can try to show code that reproduces this error if that helps, although when I was observing it, it was not deterministic.

EDIT: Title updated after we found out what was going on.

@mizzao

This comment has been minimized.

Contributor

mizzao commented Jul 25, 2013

Seems like both myself and the other user encountered this error using https://github.com/matb33/meteor-collection-hooks. Will confirm, but doesn't seem like a Meteor core bug.

@matb33

This comment has been minimized.

matb33 commented Jul 26, 2013

I've spent several hours trying to track this down. The collection hooks don't appear to be responsible -- in the case of digilord's codebase, the "user-status" smart package was responsible for causing his problems.

mizzao, that package looks like it's one of yours. Did you by any chance have that smart package enabled when you got your error?

@mizzao

This comment has been minimized.

Contributor

mizzao commented Jul 26, 2013

Hi @matb33,

Yes, I did have that package enabled. Can you send me a message with exactly what seems to be causing that error? That package is pretty simple and I'm not sure what it could be doing that would cause this.

@matb33

This comment has been minimized.

matb33 commented Jul 26, 2013

You are inserting a document into an in-memory collection (UserSessions) and manually specifying the _id. Sometimes that insert gets called multiple times with the same _id.

@mizzao

This comment has been minimized.

Contributor

mizzao commented Jul 26, 2013

I'll test for and fix that bug in my code. However, I still think that

Inserting multiple items with the same _id into a local collection results in undecipherable error

qualifies as a Meteor bug.

@mizzao

This comment has been minimized.

Contributor

mizzao commented Jul 26, 2013

@matb33 thanks for finding this. To reproduce

  foo = new Meteor.Collection(null);
  foo.insert({
    _id: "blhabahaba",
    a: 1
  });
  foo.insert({
    _id: "blhabahaba",
    a: 2
  });

On the client, this says "insert failed". On the server, it just prints the following. I think both error messages could be enhanced a bit and save some poor fool like me several hours of debugging in the future.

Error
    at app/packages/minimongo/minimongo.js:50:44
    at /home/mao/projects/CrowdMapper/.meteor/local/build/server/server.js:298:12
    at Array.forEach (native)
    at Function._.each._.forEach (/home/mao/.meteor/tools/d699ad29da/lib/node_modules/underscore/underscore.js:78:11)
    at run (/home/mao/projects/CrowdMapper/.meteor/local/build/server/server.js:239:7)
@matb33

This comment has been minimized.

matb33 commented Jul 26, 2013

@mizzao I agree the error message could be much clearer.

When the exception is thrown, it would be very beneficial for the stack trace to show the error message from the Error object.

@glasser

This comment has been minimized.

Member

glasser commented Jul 26, 2013

Thanks, minimongo errors were using a technique that led to poor stack traces. Fixed on devel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment