Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

function invocation before a client has connected and therefore "has no method" #86

Closed ghost closed 13 years ago

ghost commented 13 years ago

function created on the client; Server calls function with some data;

Client has yet to connect and I call the function (Bang!)

Object # has no method

yep could catch with a try; however should this not just be transparent; if I call a function that does not exist on the everyone.now object then it should not throw an error?

tommedema commented 13 years ago

In general: the server should never throw because of behavior implemented on the client-side. This is a bug.

dvv commented 13 years ago

The fun is that the behavior isn't implemented by the client ;) The same result will be if you call non-existent-in-the-context function even if client has been connected.

So I hardly consider this a bug -- buggy is the way the server is used. The server must ensure client is connected before it calls anything from the shared context.

tommedema commented 13 years ago

@dvv, currently, if a client manually removes this code the server may throw an error while if the client does not do this the server will not.

dvv commented 13 years ago

I don't get, sorry. Mind to drop a couple of lines of code for server and client side? TIA

tommedema commented 13 years ago

@dvv sure, although this only happens if there is not a single client with such function.

server:

everyone.on('connect', function() {
       everyone.now.iDoNotExist();
 });

client:

 //just setup now and do not add any now functions
dvv commented 13 years ago

Ah, I see now. This is the "magic" of everyone...

ericz commented 13 years ago

Here is the current behavior in the case that the client decides to change the code to remove/overwrite methods

  1. If the client removes an existing function, or overwrites with a non-function the change is not propagated up to everyone.now so everyone.now.someFunction() will always work if there has ever been a user that had the function, even if that user is disconnected or has change the methods client-side
  2. If you try to call using this.now.someFunction() on every client, and one of the client has removed their version of that function, an error will be thrown, however this will not crash the server. That client for which it did crash, and only that client, will be disconnected.
ericz commented 13 years ago

To address the original poster, although a stack trace is printed, the method he is seeing does not crash the server as NowJS catches all uncaught exceptions. Thus it is rather harmless.

The only thing you can really do is to, instead of printing the stack trace, make the error look prettier because it is impossible to make some kind of catch all method for any possible method you might want to call that doesn't exist yet

ericz commented 13 years ago

Closing due to no real solution

ericz commented 13 years ago

Please ignore above message, that commit didn't actually have anything to do with this issue.