Skip to content

Validation error "must be an object" #56

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

Open
kamranhossain opened this issue Jun 23, 2016 · 5 comments
Open

Validation error "must be an object" #56

kamranhossain opened this issue Jun 23, 2016 · 5 comments

Comments

@kamranhossain
Copy link

This is the error I find in terminal of my code. I cant resolve this exception. "Exception while invoking method 'myway.enterName' Error: The first argument of validate() or validateOne() must be an object". In console "Error invoking Method 'myway.enterName': Internal server error [500]" this error is shown.

@M-Khay
Copy link

M-Khay commented Aug 8, 2016

did you got any success on this, I'm still struggling with this. Any help will be greatly appreciated.

Thnx in advance.

@davidjcastner
Copy link

davidjcastner commented Aug 25, 2016

I am also getting the same error:

Exception while invoking method 'methodName' Error: The first argument of validate() or validateOne() must be an object

The error is caused when I attempt to call a method without an object

// example
new ValidatedMethod({
    name: 'methodName',
    validate: new SimpleSchema({ text: { type: String }}).validator(),
    run: function(data) {}
});
Meteor.call('methodName'); // causes Error: The first argument of validate() or validateOne() must be an object
Meteor.call('methodName', {}); // validation error (appropriate behavior)

Edit: I thought this was causing my server to restart, but it was a different issue. This behavior is appropriate, and what is causing it was a call to a method that expects an object. Anyone else seeing this error should check to make sure they are sending the right arguments to a method call.

@merlinstardust
Copy link

merlinstardust commented Dec 11, 2016

I would like to be able to call a ValidatedMethod without an object argument when my method definition takes no arguments.

I do understand that I could simply define these kinds of methods with the regular Meteor.methods call, but I would prefer to define all methods the same way for consistency's sake.

@AnthonyLamot
Copy link

AnthonyLamot commented Aug 1, 2017

I'm guessing this is as designed. I had the same issue but the discussion above gave me the extra "a-ha" that I needed.

You need to make sure that you pass an object when you're calling you're meteor method, because validatewill only work on objects, not single arguments.

So:

Meteor.call('AwesomeMethod', someArgument) // won't work and will result in the error in your terminal
Meteor.call('AwesomeMethod, {someArgument} // will work, because now you are putting the argument in an object, by putting {} around it

@kelvinu
Copy link

kelvinu commented Sep 3, 2017

this spoked me for a bit so i thought i'd share this.

Meteor.call('AwesomeMethod, {key: value}, callback )

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

6 participants