ecovacs-deebot.js icon indicating copy to clipboard operation
ecovacs-deebot.js copied to clipboard

Crash while trying to read undefined data

Open winnieXY opened this issue 2 years ago • 8 comments

Hey,

I've a Deebot N8 and so far the communication seems to be pretty good. However from time to time I've an issue with the library and it crashes (+ the complete nodered instance).

See the log below for details. A quickfix would be to test if the data is really there before accessing it - or (even quicker) encapsulating everything in try-catch so that at least nodered isn't crashing.

24 Sep 19:49:52 - [error] TypeError: Cannot read properties of undefined (reading 'data') at EcovacsMQTT_JSON.handleMessage (/data/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:93:38) at MqttClient. (/data/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:73:18) at MqttClient.emit (node:events:527:28) at MqttClient._handlePublish (/data/node_modules/mqtt/lib/client.js:1547:12) at MqttClient._handlePacket (/data/node_modules/mqtt/lib/client.js:535:12) at work (/data/node_modules/mqtt/lib/client.js:438:12) at Writable.writable._write (/data/node_modules/mqtt/lib/client.js:452:5) at doWrite (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139) at writeOrBuffer (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5) at Writable.write (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11) at TLSSocket.ondata (node:internal/streams/readable:754:22) at TLSSocket.emit (node:events:527:28) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at TLSSocket.Readable.push (node:internal/streams/readable:228:10) at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

winnieXY avatar Sep 24 '22 20:09 winnieXY

@winnieXY

Do I see that correctly, that problem occurs in this case with Node-RED? Can you give me more details about the circumstances under which this occurs?

mrbungle64 avatar Sep 25 '22 05:09 mrbungle64

Yes, correct.

I can extract the nodes and provide them if needed. But it's basically just data retrieval which is parsed then by node-red.

I've no clue yet which message crashed it. For the time being i added a try catch around it and some console.error things to get more details.

winnieXY avatar Sep 25 '22 06:09 winnieXY

Here we go: First again the stacktrace:

TypeError: Cannot read properties of undefined (reading 'data')
    at EcovacsMQTT_JSON.handleMessage (/data/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:94:32)
    at MqttClient.<anonymous> (/data/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:73:18)
    at MqttClient.emit (node:events:527:28)
    at MqttClient._handlePublish (/data/node_modules/mqtt/lib/client.js:1547:12)
    at MqttClient._handlePacket (/data/node_modules/mqtt/lib/client.js:535:12)
    at work (/data/node_modules/mqtt/lib/client.js:438:12)
    at Writable.writable._write (/data/node_modules/mqtt/lib/client.js:452:5)
    at doWrite (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at Writable.write (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at TLSSocket.ondata (node:internal/streams/readable:754:22)
    at TLSSocket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

This is the message which caused the crash: { td: 'GetIOTConnStatus', on: 1, conn: 2, ip: '3.127.110.57' }

This is my modification to the code for reference:

        try {
                if (type === "incoming") {
                    eventName = topic.split('/')[2];
                    message = JSON.parse(message);
                    payload = message['body']['data']; //<-- crashing here
                } else if (type === "response") {
                    resultCode = message['body']['code'];
                    resultCodeMessage = message['body']['msg'];
                    payload = message['body']['data'];
                    if (message['header']) {
                        const header = message['header'];
                        if (this.vacBot.firmwareVersion !== header['fwVer']) {
                            this.vacBot.firmwareVersion = header['fwVer'];
                            this.emit('HeaderInfo', {
                                'fwVer': header['fwVer'],
                                'hwVer': header['hwVer']
                            });
                        }
                    }
                } else if (type === "logResponse") {
                    resultCodeMessage = message['ret'];
                }
        }
        catch (error) {
            console.error(error)
            console.error(message)
        }

winnieXY avatar Sep 25 '22 08:09 winnieXY

@winnieXY

This is the message which caused the crash: { td: 'GetIOTConnStatus', on: 1, conn: 2, ip: '3.127.110.57' }

Where did you log this message and was it caused by sending a command? I think a message with this structure is a bit unusual.

mrbungle64 avatar Sep 25 '22 09:09 mrbungle64

The output ist from the second console.error statement within the catch. The stack trace is from the first console.error Statement.

winnieXY avatar Sep 25 '22 09:09 winnieXY

grafik

This is the screenshot of the Deebot node which is causing that crash. So I just use it as input - till now I've never send a command to the node.

winnieXY avatar Sep 25 '22 09:09 winnieXY

So after several days of running: It doesn't crash nodered anymore. However I see on a irregular basis these stacktraces in the error log:

[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1) TypeError: Cannot read properties of undefined (reading 'data')
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at EcovacsMQTT_JSON.handleMessage (/data/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:94:32)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient.<anonymous> (/data/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:73:18)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient.emit (node:events:527:28)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient._handlePublish (/data/node_modules/mqtt/lib/client.js:1547:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient._handlePacket (/data/node_modules/mqtt/lib/client.js:535:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at work (/data/node_modules/mqtt/lib/client.js:438:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at Writable.writable._write (/data/node_modules/mqtt/lib/client.js:452:5)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at doWrite (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at writeOrBuffer (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at Writable.write (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.ondata (node:internal/streams/readable:754:22)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.emit (node:events:527:28)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at addChunk (node:internal/streams/readable:315:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at readableAddChunk (node:internal/streams/readable:289:9)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1) { td: 'GetIOTConnStatus', on: 1, conn: 2, ip: '3.127.110.57' }
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1) TypeError: Cannot read properties of undefined (reading 'data')
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at EcovacsMQTT_JSON.handleMessage (/data/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:94:32)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient.<anonymous> (/data/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:73:18)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient.emit (node:events:527:28)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient._handlePublish (/data/node_modules/mqtt/lib/client.js:1547:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at MqttClient._handlePacket (/data/node_modules/mqtt/lib/client.js:535:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at work (/data/node_modules/mqtt/lib/client.js:438:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at Writable.writable._write (/data/node_modules/mqtt/lib/client.js:452:5)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at doWrite (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at writeOrBuffer (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at Writable.write (/data/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.ondata (node:internal/streams/readable:754:22)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.emit (node:events:527:28)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at addChunk (node:internal/streams/readable:315:12)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at readableAddChunk (node:internal/streams/readable:289:9)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1)     at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
[rgkiz ](http://localhost:2888/#/tasks/rgkizirt65zwvfn95z9low2af?log=1) { td: 'GetIOTConnStatus', on: 1, conn: 2, ip: '3.127.110.57' }

It's always the same IP which does not belong to my network. As an example I added two subsequent crashes from the error log here. Sadly I forgot to add timestamps into the log message ..

winnieXY avatar Sep 28 '22 07:09 winnieXY

@winnieXY

Thanks for the information 👍🏻 I will implement some code to handle this message when I find the time (maybe already in a few days).

mrbungle64 avatar Sep 28 '22 07:09 mrbungle64

@winnieXY

This should be fixed with version 0.4.3 of node-red-contrib-ecovacs-deebot

mrbungle64 avatar Nov 06 '22 11:11 mrbungle64