Skip to content
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

try catch for packet error catches user-defined eventlistener exceptions #95

Closed
issy123 opened this issue Feb 22, 2016 · 3 comments
Closed

Comments

@issy123
Copy link

issy123 commented Feb 22, 2016

I get packet error messages while the packets are processed perfectly correct. But the try catch block will also try and catch user-defined event listeners exceptions.

How to reproduce this?
Here is some code:

var AgarioClient = require('agario-client'); //Use next line in your scripts
var client = new AgarioClient('worker'); //create new client and call it "worker" (not nickname)

client.on('connected', function() {client.spawn("test")});

client.on("ballAction",function(){
    this.does.not.exist;//!!!
});

client.on("packetError",function(a,b,preventCrash){
    console.log("packet error");
    preventCrash();
})
AgarioClient.servers.getFFAServer({region: "EU-London"}, function(srv) {
    client.connect('ws://' + srv.server, srv.key); //do not forget to add ws://
});

The user-defined event listener functions gets executed when u .emit() an event, maybe do a try catch on that!? Or something else.

(spend hours debugging why my code wouldnt work and why it isnt showing errors XD)

@pulviscriptor
Copy link
Owner

It is an issue, all packet processors have emitters in them and if emitter crashes then processor gets this error.
Correct way to fix it is to make processors process packets without emitting events, but this needs major changes in client's architecture.
I think moving emitters inside process.nextTick will work.
Anybody have better ideas?

@issy123
Copy link
Author

issy123 commented Feb 22, 2016

Couldn't you only catch(specificError) and exclude others?
In first place it was made for an RangeError as seen here:
#46 (comment)

And as far as I know only that triggers an error

@pulviscriptor
Copy link
Owner

@issy123
To make that as i said i need to re-write processors to process only binary data and return processed packet. And if processor crashes while processing, then detect error. But its slow, hard, and i don't have free time, so i can't do that.
I need some easy solution like process.nextTick.

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

2 participants