diff --git a/nodes/core/logic/17-split.js b/nodes/core/logic/17-split.js index 522e986bd..3170ba584 100644 --- a/nodes/core/logic/17-split.js +++ b/nodes/core/logic/17-split.js @@ -312,7 +312,7 @@ module.exports = function(RED) { } }); }).catch(err => { - throw new Error(RED._("join.errors.invalid-expr",{error:e.message})); + throw new Error(RED._("join.errors.invalid-expr",{error:err.message})); }); } @@ -371,15 +371,15 @@ module.exports = function(RED) { function getInitialReduceValue(node, exp, exp_type) { return new Promise((resolve, reject) => { RED.util.evaluateNodeProperty(exp, exp_type, node, {}, - (err, result) => { - if(err) { - return reject(err); - } - else { - return resolve(result); - } - }); - }); + (err, result) => { + if(err) { + return reject(err); + } + else { + return resolve(result); + } + }); + }); } function JoinNode(n) { @@ -408,6 +408,7 @@ module.exports = function(RED) { this.reduce_fixup = (exp_fixup !== undefined) ? RED.util.prepareJSONataExpression(exp_fixup, this) : undefined; } catch(e) { this.error(RED._("join.errors.invalid-expr",{error:e.message})); + return; } } diff --git a/test/nodes/core/logic/17-split_spec.js b/test/nodes/core/logic/17-split_spec.js index 564fd720d..bafdb0281 100644 --- a/test/nodes/core/logic/17-split_spec.js +++ b/test/nodes/core/logic/17-split_spec.js @@ -1409,7 +1409,7 @@ describe('JOIN node', function() { }); }); - it('should handle invalid JSON expression"', function (done) { + it('should handle invalid JSONata reduce expression - syntax error"', function (done) { var flow = [{ id: "n1", type: "join", mode: "reduce", reduceRight: false, @@ -1433,6 +1433,77 @@ describe('JOIN node', function() { }); }); + it('should handle invalid JSONata reduce expression - runtime error"', function (done) { + var flow = [{ + id: "n1", type: "join", mode: "reduce", + reduceRight: false, + reduceExp: "$uknown()", + reduceInit: "0", + reduceInitType: "num", + reduceFixup: undefined, + wires: [["n2"]] + }, + { id: "n2", type: "helper" }]; + helper.load(joinNode, flow, function () { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + setTimeout(function () { + done(); + }, TimeoutForErrorCase); + n2.on("input", function (msg) { + done(new Error("This path does not go through.")); + }); + n1.receive({ payload: "A", parts: { id: 1, type: "string", ch: ",", index: 0, count: 1 } }); + }); + }); + + it('should handle invalid JSONata fixup expression - syntax err"', function (done) { + var flow = [{ + id: "n1", type: "join", mode: "reduce", + reduceRight: false, + reduceExp: "$A", + reduceInit: "0", + reduceInitType: "num", + reduceFixup: "invalid expr", + wires: [["n2"]] + }, + { id: "n2", type: "helper" }]; + helper.load(joinNode, flow, function () { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + setTimeout(function () { + done(); + }, TimeoutForErrorCase); + n2.on("input", function (msg) { + done(new Error("This path does not go through.")); + }); + n1.receive({ payload: "A", parts: { id: 1, type: "string", ch: ",", index: 0, count: 1 } }); + }); + }); + it('should handle invalid JSONata fixup expression - runtime err"', function (done) { + var flow = [{ + id: "n1", type: "join", mode: "reduce", + reduceRight: false, + reduceExp: "$A", + reduceInit: "0", + reduceInitType: "num", + reduceFixup: "$unknown()", + wires: [["n2"]] + }, + { id: "n2", type: "helper" }]; + helper.load(joinNode, flow, function () { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + setTimeout(function () { + done(); + }, TimeoutForErrorCase); + n2.on("input", function (msg) { + done(new Error("This path does not go through.")); + }); + n1.receive({ payload: "A", parts: { id: 1, type: "string", ch: ",", index: 0, count: 1 } }); + }); + }); + it('should concat payload when group.type is array', function (done) { var flow = [{ id: "n1", type: "join", wires: [["n2"]], build: "array", mode: "auto" }, { id: "n2", type: "helper" }];