hortinstein / node-dash-button

A small module to emit events when an Amazon Dash Button is pressed
949 stars 94 forks source link

Uncaught error crashes node app #14

Closed marksuman closed 8 years ago

marksuman commented 8 years ago

My node app that uses this module occasionally halts with the following error and stack trace:

/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/tcp.js:150
            throw new Error("Don't know how to process TCP option " + raw_packet[offset]);
            ^

Error: Don't know how to process TCP option 34
    at TCPOptions.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/tcp.js:150:19)
    at TCP.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/tcp.js:231:22)
    at IPv4.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/ipv4.js:97:58)
    at EthernetPacket.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/ethernet_packet.js:40:51)
    at PcapPacket.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/pcap_packet.js:37:57)
    at Function.decode (/Users/mark/bin/dash-dispatch/node_modules/pcap/decode/index.js:11:36)
    at PcapSession.<anonymous> (/Users/mark/bin/dash-dispatch/node_modules/node-dash-button/index.js:66:34)
    at emitOne (events.js:77:13)
    at PcapSession.emit (events.js:169:7)
    at PcapSession.on_packet_ready (/Users/mark/bin/dash-dispatch/node_modules/pcap/pcap.js:99:10)
    at packet_ready (/Users/mark/bin/dash-dispatch/node_modules/pcap/pcap.js:44:14)

I'm running this on OS X 10.11. Could I detect this error in something like dash.on("error", function(err)...? Or does it go deeper out of my control?

hortinstein commented 8 years ago

this seems similar to #6 he got a node_pcap: EthernetFrame() - Don't know how to decode ethertype 34958

What I should do is add a pcap_session.on("error", function(err)... like you mentioned when I register the dash so it could fail gracefully and I could restart the pcap stream. I will add it soon. Thanks for the feedback!

alexprice1 commented 8 years ago

Any update on this? I am seeing this error also

hortinstein commented 8 years ago

sorry, i have not been able to replicate it yet. How often are you seeing it? I will try to allow for errors soon, I apologize for the delay, masters degree work and my job have been eating my time lately, even though this would be pretty trivial to implement.

I would be happy to accept any pull requests that add in the functionality though!

alexprice1 commented 8 years ago

I have not been able to replicate it again. I am thinking it is specifically an error with node_pcap. I am considering just wrapping it in a try/catch and throwing out the error.

hortinstein commented 8 years ago

ok, if you find something that works let me know. I will embed it in the module. Thanks for your feedback!

On Mon, Nov 30, 2015 at 10:47 PM, Alexander Price notifications@github.com wrote:

I have not been able to replicate it again. I am thinking it is specifically an error with node_pcap. I am considering just wrapping it in a try/catch and throwing out the error.

— Reply to this email directly or view it on GitHub https://github.com/hortinstein/node-dash-button/issues/14#issuecomment-160843805 .

ecaron commented 8 years ago

Looks like this is heavily related to https://github.com/mranney/node_pcap/issues/153, where node_pcap mixes mechanisms of logging & throwing errors. Unfortunately I don't think pcap can fix this without introducing some breaking changes (because at present other libraries are built to expect errors thrown in some situations, and emitted in others).

I'll submit a PR that does a try/catch (since for node-dash-button's use case we don't care about these errors anyway).

alexprice1 commented 8 years ago

@ecaron good thought. I went ahead and just wrapped it in a try/catch for myself.

ecaron commented 8 years ago

PR has been submitted - https://github.com/hortinstein/node-dash-button/pull/23

hortinstein commented 8 years ago

23 has been merged and updated to NPM, please reopen if there are any issues.