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

Channel error chaining #17

Closed
lukyer opened this issue May 19, 2016 · 3 comments
Closed

Channel error chaining #17

lukyer opened this issue May 19, 2016 · 3 comments

Comments

@lukyer
Copy link

lukyer commented May 19, 2016

If error occurs during 1. write(), no other write() can end with success. Both callback/promise approaches are problematic.

Example:

var chan = conn.openChannel();
    chan.write('/ip/address/printXcauseError', function() {
        chan.on('done', function(data) {
            var parsed = MikroNode.parseItems(data);
            parsed.forEach(function(item) {
                console.log('Interface/IP: ' + item.interface + "/" + item.address);
            });
        });
        chan.once('trap', function(trap, chan) {
            console.log('Command failed: ' + trap);
        });
        chan.once('error', function(err, chan) {
            console.log('Oops: ' + err);
        });
    });
    chan.write('/ip/address/print', function() {
        chan.on('done', function(data) {
            var parsed = MikroNode.parseItems(data);
            parsed.forEach(function(item) {
                console.log('Interface/IP: ' + item.interface + "/" + item.address);
            });
        });
        chan.once('trap', function(trap, chan) {
            console.log('Command failed: ' + trap);
        });
        chan.once('error', function(err, chan) {
            console.log('Oops: ' + err);
        });
    });
    chan.close();

Expected result:
Command failed: no such command()
Interface/IP: ether2-master-local/10.245.235.1/24
Interface/IP: internal-mikrotik/192.168.88.1/24

Obtained result:
Command failed: no such command()
Command failed: no such command()

@lukyer
Copy link
Author

lukyer commented May 19, 2016

According to debug output, it is probably caused because of every command issued on the same channel sets .tag to the same value. Then error is probably returned by mikrotik because of that same tag id.

@gtjoseph
Copy link
Collaborator

Create a pull request in my repo (https://github.com/f5eng/mikronode-ng) and I'll test and merge it, then publish to npm (mikronode-ng).

@Trakkasure
Copy link
Owner

Thanks for your work on this code base. I have, in the past couple of months, updated to ES2015 code syntax and wrote a babel plugin to provide private class properties.
In addition, I have changed the socket reader, sentence parser, connection, and channel data configuration to use RxJS streams. It does still support events.

Also, this issue has a configurable result with a new option (closeOnTrap).

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

3 participants