1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix error reporting of invalid jsonata in Join/reduce

This commit is contained in:
Nick O'Leary 2018-07-27 09:43:22 +01:00
parent 2000cadb17
commit 450f4d9a5a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 83 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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" }];