New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught Exception crashing Node-RED | When the connect action on MQTT is performed with undefined
values
#4380
Comments
Hi, thanks for reporting. I can confirm this happens in NR 3.0.2 as well. Do you have a newer Node-RED v3.1.0 that you could test this on also? |
To be clear, this has nothing to do with global variables. The issue is because your code is trying to initialise an MQTT connection with bad ( The correct course of action would be to raise a catchable error (or output a "warn" to the sidebar) that invalid variables were provided in the connection object. |
Updated flow demonstrating the issue (using
The exception:
|
undefined
values
Current Behavior
There comes an exception if the global variables are not defined and we try to read them and apply the configuration to MQTT via msg properties.
28 Sep 12:53:23 - [error] TypeError: Cannot read properties of undefined (reading 'indexOf')
at MQTTBrokerNode.node.setOptions (C:\Users###\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\nodes\core\network\10-mqtt.js:590:33)
at C:\Users###\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\nodes\core\network\10-mqtt.js:423:37
at _callback (C:\Users###\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\nodes\core\network\10-mqtt.js:834:62)
at C:\Users###\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\nodes\core\network\10-mqtt.js:869:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)`
Expected Behavior
There should be an error message if the global variables are not defined are being forced to the MQTT.
Steps To Reproduce
The reproduction flow is attached to this issue.
Example flow
[
{
"id": "2c726c6c8c237557",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "3270f5029c4593da",
"type": "function",
"z": "2c726c6c8c237557",
"name": "function 10",
"func": "//Configuration data for the mqtt\nmsg.action = "connect"\n\n\nmsg.broker = {\n "broker": global.get("HelowWorld"),\n "port": global.get("MqttPort"),\n "clientid": global.get("MqttClientId"),\n "username": global.get("MqttUserName"),\n "password": global.get("MqttPassword"),\n "force": true,\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1190,
"y": 380,
"wires": [
[
"929e99eb6924d1b5"
]
]
},
{
"id": "ee2f604b237e553a",
"type": "inject",
"z": "2c726c6c8c237557",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 840,
"y": 380,
"wires": [
[
"3270f5029c4593da"
]
]
},
{
"id": "929e99eb6924d1b5",
"type": "mqtt out",
"z": "2c726c6c8c237557",
"name": "Sending_Reset_Signals",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "0ff7e11968ee8724",
"x": 1510,
"y": 460,
"wires": []
},
{
"id": "0ff7e11968ee8724",
"type": "mqtt-broker",
"name": "",
"broker": "123.125.123.10",
"port": "8883",
"tls": "4dc487b6.a817e8",
"clientid": "",
"autoConnect": true,
"usetls": true,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": "",
"credentials": {}
},
{
"id": "4dc487b6.a817e8",
"type": "tls-config",
"name": "Broker TLS",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "server.pem",
"servername": "",
"verifyservercert": false,
"alpnprotocol": ""
}
]
Environment
The text was updated successfully, but these errors were encountered: