insectos / node-red-ssh-exec

NodeRED Node for SSH
Apache License 2.0
2 stars 2 forks source link

TypeError: Cannot read properties of undefined (reading '0') #11

Open novski opened 10 months ago

novski commented 10 months ago

Describe the bug I set up an ssh connection that works from cli on NR host. Proved by executing ssh node-red while "node-red" is the Host in my config file not the hostname of the remote client.

Then I tried to execute a primitive cli command like pwd but got an TypeError: Cannot read properties of undefined (reading '0') back from the catch node. As next, I tried to execute the pwd with a newline as mentioned in the readme. pwd \n Somehow that generates some (I assume) escape, see below pwd \\n.

To Reproduce Steps to reproduce the behavior:

  1. Maybe use this small flow below
  2. create RSA key without passphrase
  3. write config.
    [
    {
        "id": "d77bd36f191e36e1",
        "type": "ssh-exec",
        "z": "eb5fe652f01eee64",
        "sshconfig": "node-red",
        "name": "octopi",
        "host": "octopi",
        "port": 22,
        "username": "myUser",
        "x": 660,
        "y": 1960,
        "wires": [
            [
                "6fc200658a27e452"
            ]
        ]
    },
    {
        "id": "f34dc88b3da3f789",
        "type": "catch",
        "z": "eb5fe652f01eee64",
        "name": "",
        "scope": [
            "d77bd36f191e36e1"
        ],
        "uncaught": false,
        "x": 630,
        "y": 2020,
        "wires": [
            [
                "813e2d54241e3ee4"
            ]
        ]
    },
    {
        "id": "6fc200658a27e452",
        "type": "debug",
        "z": "eb5fe652f01eee64",
        "name": "debug 71",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 1960,
        "wires": []
    },
    {
        "id": "813e2d54241e3ee4",
        "type": "debug",
        "z": "eb5fe652f01eee64",
        "name": "debug 72",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 2020,
        "wires": []
    },
    {
        "id": "a68ff67b1c2be3ac",
        "type": "inject",
        "z": "eb5fe652f01eee64",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "sshhost",
                "v": "octopi",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "pwd \\n",
        "payloadType": "str",
        "x": 450,
        "y": 1960,
        "wires": [
            [
                "d77bd36f191e36e1"
            ]
        ]
    }
    ]

Expected behavior to get the path of my remote client connection back.

Screenshots Bildschirmfoto 2024-01-02 um 11 56 35

Workstation / Process / Context

Full NR debug object:

{"_msgid":"4838c5529e8f2b21","payload":"pwd \\n","sshhost":"octopi","error":
  {"message":"TypeError: Cannot read properties of undefined (reading '0')","source": 
    {"id":"d77bd36f191e36e1","type":"ssh-exec","name":"octopi","count":1},
    "stack":"TypeError: Cannot read properties of undefined (reading '0')
    at createConnectCfg (/home/pi/.node-red/node_modules/@insectos/ssh-exec/ssh-exec/utils.js:92:38)
    at Object.processMessage (/home/pi/.node-red/node_modules/@insectos/ssh-exec/ssh-exec/utils.js:216:24)
    at SshExec._inputCallback (/home/pi/.node-red/node_modules/@insectos/ssh-exec/ssh-exec/ssh-exec.js:27:13)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:214:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:206:11)
    at Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:190:25)
    at Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:499:10)
    at deliverMessageToDestination (/usr/lib/node_modules/node-red/node_modules/@node..."}}
novski commented 10 months ago

I found this issue #2 and tried the same with a function node:

[
    {
        "id": "d77bd36f191e36e1",
        "type": "ssh-exec",
        "z": "eb5fe652f01eee64",
        "sshconfig": "node-red",
        "name": "octopi",
        "host": "octopi",
        "port": 22,
        "username": "myUser",
        "x": 720,
        "y": 3080,
        "wires": [
            [
                "6fc200658a27e452"
            ]
        ]
    },
    {
        "id": "f34dc88b3da3f789",
        "type": "catch",
        "z": "eb5fe652f01eee64",
        "name": "",
        "scope": [
            "d77bd36f191e36e1"
        ],
        "uncaught": false,
        "x": 690,
        "y": 3140,
        "wires": [
            [
                "813e2d54241e3ee4"
            ]
        ]
    },
    {
        "id": "6fc200658a27e452",
        "type": "debug",
        "z": "eb5fe652f01eee64",
        "name": "debug 71",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 3080,
        "wires": []
    },
    {
        "id": "813e2d54241e3ee4",
        "type": "debug",
        "z": "eb5fe652f01eee64",
        "name": "debug 72",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 3140,
        "wires": []
    },
    {
        "id": "a68ff67b1c2be3ac",
        "type": "inject",
        "z": "eb5fe652f01eee64",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 330,
        "y": 3080,
        "wires": [
            [
                "ca19e955d44b9025"
            ]
        ]
    },
    {
        "id": "ca19e955d44b9025",
        "type": "function",
        "z": "eb5fe652f01eee64",
        "name": "payload:pwd\\n",
        "func": "msg.payload = \"pwd\\n\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 3080,
        "wires": [
            [
                "d77bd36f191e36e1",
                "363fc4aa7fa933d8"
            ]
        ]
    },
    {
        "id": "363fc4aa7fa933d8",
        "type": "debug",
        "z": "eb5fe652f01eee64",
        "name": "debug 73",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 700,
        "y": 3020,
        "wires": []
    }
]

I think there are more Problems. Why does the node export above show myUser? If I configure to use the config file, it should use the user set in the config. As well as not setting a user leads to an error on deploy because NR thinks the node is not properly configured. Bildschirmfoto 2024-01-02 um 12 30 46 If the two are not related, you can tell me and I will create two separate issues...

Stwissel commented 10 months ago

The cannot read [0] is a result of the ssh-config object not found. handled in 0.3.5

novski commented 10 months ago

The "can not read properties of undefined (reading '0')" is now fixed.

B0rax commented 5 months ago

I installed this node today (0.3.2) and I am encountering that error. When will the fix be pushed to the repository?

Stwissel commented 5 months ago

0.3.5?

Stwissel commented 5 months ago

The package name has changed to

@insectos/node-red-ssh-exec v0.3.5