Giter VIP home page Giter VIP logo

stampit-event-bus's People

Contributors

stefanpoeter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stampit-event-bus's Issues

TypeError: Cannot read property 'apply' of undefined

Stack trace from error:

at Object emit (.../stampit-event-bus/src/stampit-event-bus.js:22:37)
at Object.<anonymous> (.../jsmodbus/src/modbus-tcp-client.js:55:12)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1073:10)

This happens when I start my server which utilizes the jsmodbus package. I've run into this issue on two deployments now; the first one, I'm ashamed to admit, I edited your source code to just check if (cbList[name][i]) before the erroring line 24. I ran into the issue again today when deploying a new server and thought I'd send in an issue. I did some debugging of my own and found that the issue happens in this section of the stampit-event-bus.js:

for (var i in cbList[name]) {
    cbList[name][i].listener.apply(this, args);
    // remove if once === true
    if (cbList[name][i] && cbList[name][i].once) {
        cbList[name].splice(i, 1);-+}
    }
}

If I add console.log(i) before that cbList[name][i].listener.apply(this, args); line, I can see that this issue doesn't happen when i represents integer values (usually 0, even though technically it is typeof string at that moment) but rather that the error fires when the value of i is "getIndexBy". I tried, but it is beyond my depth to determine for certain where that 'getIndexBy" is coming from or why. For the moment, to get my system running, I have added (based on MDN articles about for...in usage) a hasOwnProperty check to make that for loop:

for (var i in cbList[name]) {
    if (cbList[name].hasOwnProperty(i)) {
        cbList[name][i].listener.apply(this, args);
    };
    // remove if once === true
    if (cbList[name][i] && cbList[name][i].once) {
        cbList[name].splice(i, 1);
    }
}

With my patched line making sure that the key in i for that loop iteration actually exists as a property of cbList[name], everything seems to work correctly; the listener.apply line still executes as it would have before; but the error is eliminated.

FWIW: this is running on debian jesse on a Raspberry Pi 3 (and getting jsmodbus, more specifically its serialport dependency, to install on Raspberry Pi is a TRICK and a half since the new PIXEL RPi OS came out)

Thanks for your assistance and all your great work, the jsmodbus library is extremely useful to me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.