Can't analyze error object (return from method call)! Totally stumped


So in a method call, I’ve got this code:

    if newUserId # successfully made new user
      Accounts.sendVerificationEmail newUserId
      return { success: true }
      throw new Meteor.Error 'user-exists', 'User already exists.'

And back in the script that calls the method: 'createSeller', newUser, (error, result) ->
          Session.set 'creatingUser', false
          console.dir error

I would expect it to dump out the error object and show its properties and values, but instead it just dumps out the following:

Error: Username already exists. [403]
Stack trace:

I don’t get it. Why is it dumping all this out? typeof error returns “object.” Then why do console.dir and console.log not show it as it shows most objects? e.g.:

Object { name: "Bob", age: 48 }


This error might be coming from sendVerificationEmail call. try reseting your app with meteor reset on the shell. and try again.

sendVerificationEmail might not send an email if the user already exists.


Hmm, now I get this:

"Exception in delivering result of invoking ‘createSeller’: [“submit form”]/</<@http://localhost:3000/client/templates/seller/

That error doesn’t tell me much, unfortunately. Could use a little more detail.


you must be doing something else in the method before if(newUserId) that is causing that exception


Full method:

  createSeller: (userData) ->
    check userData,
      username: String
      email: String
      password: String
      profile: Match.Optional Match.ObjectIncluding({accountType: String})

    newUserId = Accounts.createUser
      username: userData.username
      password: userData.password
        accountType: 'seller'

    if newUserId # successfully made new user
      Accounts.sendVerificationEmail newUserId
      return { success: true }
      throw new Meteor.Error 'user-exists', 'User already exists.'


Okay @Murwade, I figured out where the problem is but don’t know why. Any error I throw after the Accounts.createUser call returns a 403, no matter what error I want to throw.


That’s because you already have an error thown from within Accunts.createUser before your if control runs.

What you should do is:

  • if you are calling Accounds.createUser from the client, use its callback to get the error object
  • if you are on the server, then use either Accounts.validateNewUser or Accounts.onCreateUser the latter which provides a good set of tools

These options are good for checking/manipulating the user object before its creation.

To do further tasks after the creation, you can use one of:

Or craft it manually using one of these patterns:

This one taken from

Meteor.users.find({ initialized: { $exists: false } }, { fields: { _id: 1 } }).observe({
  added: function (user) {
    // insert default user docs here if not already present
   Meteor.users.update(user._id, { $set: {initialized: true} });

or this one using the undocumented Meteor.users._makeNewID() call

  // Hack to create user id so that we can initialize is counts.
  user._id = Meteor.users._makeNewID();
  // do something with this userId
  return user;

Roles package problem
Add Accounts.onLogout