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

needs to be reworked to pass parse errors back #6

Open
chadxz opened this issue Oct 6, 2014 · 0 comments
Open

needs to be reworked to pass parse errors back #6

chadxz opened this issue Oct 6, 2014 · 0 comments

Comments

@chadxz
Copy link
Collaborator

chadxz commented Oct 6, 2014

tl;dr: if we can get parse errors to be passed back to the caller of library methods, it would be a lot easier to determine whether errors are occurring in the library as opposed to consumer code.


This library needs to be reworked so that any parse error that occurs is reported as an error to the calling method. for example, getActiveSessions should call its callback with an error if there is an error parsing any of the records passed to the parse routine.

In order to make that happen, we need to setup the state of the library after connect so that only valid data is passed into the parse routine. This should be fairly straightforward. As it is, the only invalid data that is passed to the parse routine is the welcome message. If we can find some way to consume the welcome message prior to allowing any commands to be sent to the TURN server, then the TCP client stream should only contain the data relevant to the command issued by a method call.

I took a quick stab at this and couldn't really get it working, so I bailed due to time constraints. The idea I had was to wait and fire the onConnect callback passed into the constructor until after the welcome message had been successfully cleared from the TCP client stream. I tried this by adding a readable event listener:

var options = this.options;
client = net.connect(port, host);
client.on('readable', function () {
  client.read();
  if(options.onConnect) {
    options.onConnect();
  }
});

But for whatever reason, the data I tried to read was null, and the welcome message was still in the stream when my sample code called getActiveSessions(), which caused the parser to spit back a parse error prior to actually beginning to parse meaningful data.

The parse will also need to be coded to support the 0 sessions use case, where when you do ps and there are no sessions, it just says:


    Total Sessions: 0

Right now the parser throws a parse error for this. We would need the library to not throw an error in this case.

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

1 participant