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:
parent
2000cadb17
commit
450f4d9a5a
@ -312,7 +312,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).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) {
|
function getInitialReduceValue(node, exp, exp_type) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
RED.util.evaluateNodeProperty(exp, exp_type, node, {},
|
RED.util.evaluateNodeProperty(exp, exp_type, node, {},
|
||||||
(err, result) => {
|
(err, result) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return resolve(result);
|
return resolve(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function JoinNode(n) {
|
function JoinNode(n) {
|
||||||
@ -408,6 +408,7 @@ module.exports = function(RED) {
|
|||||||
this.reduce_fixup = (exp_fixup !== undefined) ? RED.util.prepareJSONataExpression(exp_fixup, this) : undefined;
|
this.reduce_fixup = (exp_fixup !== undefined) ? RED.util.prepareJSONataExpression(exp_fixup, this) : undefined;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
this.error(RED._("join.errors.invalid-expr",{error:e.message}));
|
this.error(RED._("join.errors.invalid-expr",{error:e.message}));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 = [{
|
var flow = [{
|
||||||
id: "n1", type: "join", mode: "reduce",
|
id: "n1", type: "join", mode: "reduce",
|
||||||
reduceRight: false,
|
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) {
|
it('should concat payload when group.type is array', function (done) {
|
||||||
var flow = [{ id: "n1", type: "join", wires: [["n2"]], build: "array", mode: "auto" },
|
var flow = [{ id: "n1", type: "join", wires: [["n2"]], build: "array", mode: "auto" },
|
||||||
{ id: "n2", type: "helper" }];
|
{ id: "n2", type: "helper" }];
|
||||||
|
Loading…
Reference in New Issue
Block a user