From fbde0091de47a8393e8e541bebc973b51fa0f721 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Sun, 4 Sep 2022 11:08:41 +0100 Subject: [PATCH] fix node-red crash with invalid mqtt birth topic fixes #3865 --- .../@node-red/nodes/core/network/10-mqtt.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index 9e6195b5d..532d54d8e 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -991,14 +991,21 @@ module.exports = function(RED) { } if (topicOK) { - node.client.publish(msg.topic, msg.payload, options, function(err) { - done && done(err); - return - }); + node.client.publish(msg.topic, msg.payload, options, function (err) { + if (done) { + done(err) + } else { + node.error(err, msg) + } + }) } else { - const error = new Error(RED._("mqtt.errors.invalid-topic")); - error.warn = true; - done(error); + const error = new Error(RED._("mqtt.errors.invalid-topic")) + error.warn = true + if (done) { + done(error) + } else { + node.warn(error, msg) + } } } };