KevinBonnoron / node-red-contrib-freebox

4 stars 4 forks source link

Lan-browser gets NR to crash on an uncaught error #106

Closed NiasDune closed 8 months ago

NiasDune commented 8 months ago

Hello,

Using the lan-brower node on dockerized Node Red. Works almost nice but sometimes crashes on an uncaught error inside the node. Uncaught errors leads to a NR shutdown :( Here is an extract from the docker journal :

2 Jan 11:25:37 - [info] Connecting to freebox at https://mafreebox.freebox.fr:443 2 Jan 11:25:37 - [info] [mqtt-broker:MQTT Broker] Connected to broker: mqtt://192.168.0.5:1883 2 Jan 11:25:37 - [info] GET /lan/browser/pub 2 Jan 11:25:37 - [error] Error: connect ECONNREFUSED 127.0.0.1:80 2 Jan 11:25:37 - [red] Uncaught Exception: 2 Jan 11:25:37 - [error] TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined at new NodeError (node:internal/errors:372:5) at Hmac.update (node:internal/crypto/hash:105:11) at /data/node_modules/node-red-contrib-freebox/src/nodes/freebox-server/freebox-server.js:189:73 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async FreeboxServerNode.apiCall (/data/node_modules/node-red-contrib-freebox/src/nodes/freebox-server/freebox-server.js:232:7)

Node Red v3.0.2 node-red-contrib-freebox v0.0.17

Thanks, ND

KevinBonnoron commented 8 months ago

Hello.

Could you share the flow you are using please?

I think i found a bug with the "api" node. If you use it for a GET request but you pass it a msg.payload (which are sent as body) there is an error triggered. BY removing the msg.payload i don't have the issue anymore.

NiasDune commented 8 months ago

Hello

Sorry for the delay, I've moved to another solution in the meantime (through another plugin in a Domoticz setup). To answer your request, I've rewired the culprit flow, here it is, it's pretty simple, the goal was to find if a particular device is connected to trigger a switch in Domoticz. I've not wired the Domoticz com part.

[
    {
        "id": "c53a83b206a7dc09",
        "type": "tab",
        "label": "Détection présence",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e4268819e3833cf1",
        "type": "function",
        "z": "c53a83b206a7dc09",
        "name": "connectedDevicesInOffice",
        "func": "let arrObjs = msg.payload;\n\nmsg.payload = false;\n\n// Initialize array of MAC Adresses to check\nlet macAddressesArray = ['30:85:a9:9d:03:48'];\n\n// Initialize an array to store values\nlet devicesArray = [];\n\n// Iterate through the array of objects\nfor (let obj of arrObjs) {\n    // Check if the \"reachable\" property is true\n    if (obj.reachable) {\n        // check MAC address\n        let curr_mac = obj.id;\n        for (let macAddress in macAddressesArray) {\n            if (curr_mac.includes(macAddress)) {\n                msg.payload = obj;\n                break;\n            }\n        }\n    }\n}\n\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 590,
        "y": 500,
        "wires": [
            [
                "84551e8e9c2e31a7"
            ]
        ]
    },
    {
        "id": "84551e8e9c2e31a7",
        "type": "debug",
        "z": "c53a83b206a7dc09",
        "name": "debug 10",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 400,
        "wires": []
    },
    {
        "id": "2d0408ae637cf668",
        "type": "lan-browser",
        "z": "c53a83b206a7dc09",
        "name": "",
        "server": "5c8a37cb03fbb4ae",
        "x": 310,
        "y": 500,
        "wires": [
            [
                "e4268819e3833cf1",
                "f3e1e8bd0c455fe9"
            ]
        ]
    },
    {
        "id": "d64540f763a07c1f",
        "type": "inject",
        "z": "c53a83b206a7dc09",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 500,
        "wires": [
            [
                "2d0408ae637cf668"
            ]
        ]
    },
    {
        "id": "f3e1e8bd0c455fe9",
        "type": "debug",
        "z": "c53a83b206a7dc09",
        "name": "debug 11",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 380,
        "wires": []
    },
    {
        "id": "5c8a37cb03fbb4ae",
        "type": "freebox-server",
        "host": "https://mafreebox.freebox.fr",
        "port": "443"
    }
]

As a reminder, flow was working fine, but sometimes led everything to crash.

Hope this helps.

All the best,

ND

KevinBonnoron commented 8 months ago

OK my investigation was correct. If you remove every parameters from the "inject" node i did not have the issue anymore (btw i had it directly after importing your flow).

I will do a quick fix with a new version today. Thanks for the time you spent for the feedback

KevinBonnoron commented 8 months ago

I made a new version today (0.0.18) with the fix. If by any chance you use this palette again and have any issue feel free to report it.

Thanks again for helping me improve this palette.