Meteor.call() simulation for server only method

I implemented a very simple Meteor method which is defined on server side only and is called by the client. From time to time the method is not called on the server but the client performs a simulation (and does not even run through the server method) which returns an undefined result but no error and therefore the client code fails. As the server side method is defined in a file that is available on the server only I expect the client not to run a simulation as described here.

For the following small example I would simply like to define that no simulation is performed at all but the calling client code fails, when the server is unavailable. Can someone give me a hint about what I am doing wrong or what I am missing to get this simple example working as expected?

Thank you very much…

// Server code (defined in /imports/api/.../server/server-method.js)
// I also tried /server/server-method.js with the same result
Meteor.methods({
  getSecureString: function() {
    if (this.userId == null) {
      throw new Meteor.Error(
        'No user logged in. Please login in user and try again.'
      );
    }
    return {
      stringValue: 'This is a test...',
    };
  },
});

// Client code
Meteor.call('getSecureString', function(error, result) {
  if (error) {
    console.error(error.message);
    // alert(error);
  } else {
    console.log('Secure-String: ' + result.stringValue);
  }
});

I forgot to mention the error message which is:

“Exception in delivering result of invoking ‘getSecureString’: TypeError: Cannot read property ‘stringValue’ of undefined”

I just copied your code into a small Meteor app, and it worked as expected. Is there some other code that might interfere?

Can you explain how you discovered that it was running a simulation?

I debugged Meteor.call() and ended up in livedata_connection.js line 600/601 within the function ‘apply(name, args, options, callback)’ where alreadyInSimulation is set to true because enclosure.isSimulation is also true.

In line 679 the function returns ‘undefined’. The code is commented with:

// If we're in a simulation, stop and return the result we have,
// rather than going on to do an RPC. If there was no stub,
// we'll end up returning undefined.

There might be in deed some code that interferes within our non trivial application. I will try to create an example that enables us to reproduce the behaviour.

Did you check the client codes? I think if you don’t required the server-method.js file on the client files, then that method will not be available on client side and Meteor won’t run a simulation on the client.

The simulation should never be run and the server-method.js is intentionally only available on the server.