matteodem/meteor-boilerplate

Error: Did not check() all arguments during call to '/Websites/update'

p4t0k opened this issue · 3 comments

p4t0k commented

Hi, this is part of an app I'm currently developing...

client/modules/listWebsitesRating/listWebsitesRating.js:

Template['listWebsitesRating'].events({
    "click .ratingPlus": function (event) {
      Websites.update(this._id, {$inc: {'score': 1}});
      return false;
    },
    "click .ratingMinus": function (event) {
      Websites.update(this._id, {$inc: {'score': -1}});
      return false;
    }
});

(subscription is inside a parent module)

server/publications/WebsitesPub.js:

Meteor.publish('Websites', function () {
  return Websites.find();
});

All what this part does is that when user clicks on + or -, it changes rating (or score) of webpage. But in the server side console it throws an error:

I20150420-21:58:29.296(2)? Exception while invoking method '/Websites/update' Error: Did not check() all arguments during call to '/Websites/update'
I20150420-21:58:29.297(2)?     at [object Object]._.extend.throwUnlessAllArgumentsHaveBeenChecked (packages/check/match.js:357:1)
I20150420-21:58:29.328(2)?     at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/match.js:112:1)
I20150420-21:58:29.329(2)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1614:1)
I20150420-21:58:29.329(2)?     at packages/ddp/livedata_server.js:648:1
I20150420-21:58:29.329(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150420-21:58:29.329(2)?     at packages/ddp/livedata_server.js:647:1
I20150420-21:58:29.330(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150420-21:58:29.330(2)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150420-21:58:29.331(2)?     at packages/ddp/livedata_server.js:546:1

and on client side javascript console:

update failed: Internal server error

Although the app is working quite well, it's simply annoying... I've searched on the internet, found I should use check() method on server side, but I don't understand how to use it, when my published function doesn't take any arguments. Maybe the problem is that I should call update inside of the published server function instead of a client function? thx

UPDATED:

Okay... I added this peace of code to startup/methods.js (not sure if it's right place, but for now it's good enough):

Meteor.methods({
    ratingUpdate: function(id, num){
    check(id, String);
    check(num, Number);
    Websites.update(id, {$inc: {'score': num}});
    }});

Instead of directly calling Websites.update(), I'm calling this:

Meteor.call('ratingUpdate', this._id, -1, function (err, result) { if(err) { console.log(err); }}); 

so I'm able to handle error logging much better, but the error in server console is still the same (except the name of called function of curse). But now I at least know that this is not probably meteor-boilerplate issue, so accept my apology.

Try removing following package: matteodem:easy-security

p4t0k commented

Ok, this works for me, thanks. But what if I would like to use easy-security to add rate limit for methods? Is it bug, or am I doing anything wrong?

Yeah, it's a known bug. see matteodem/meteor-easy-security#12