diff --git a/nodes/core/logic/15-change.js b/nodes/core/logic/15-change.js index 4a1ce33ec..2c1443846 100644 --- a/nodes/core/logic/15-change.js +++ b/nodes/core/logic/15-change.js @@ -143,7 +143,7 @@ module.exports = function(RED) { if (rule.fromt === "msg") { resolve(RED.util.getMessageProperty(msg,rule.from)); } else if (rule.fromt === 'flow' || rule.fromt === 'global') { - var contextKey = RED.util.parseContextStore(rule.from); + var contextKey = RED.util.parseContextStore(rule.from); node.context()[rule.fromt].get(contextKey.key, contextKey.store, (err,fromValue) => { if (err) { reject(err); @@ -166,12 +166,10 @@ module.exports = function(RED) { try { fromRE = new RegExp(fromRE, "g"); } catch (e) { - reject(new Error(RED._("change.errors.invalid-from",{error:e.message}))); - return; + return Promise.reject(new Error(RED._("change.errors.invalid-from",{error:e.message}))); } } else { - reject(new Error(RED._("change.errors.invalid-from",{error:"unsupported type: "+(typeof fromValue)}))); - return; + return Promise.reject(new Error(RED._("change.errors.invalid-from",{error:"unsupported type: "+(typeof fromValue)}))); } return { fromType, diff --git a/test/nodes/core/logic/15-change_spec.js b/test/nodes/core/logic/15-change_spec.js index bbba27dc3..47d93ff92 100644 --- a/test/nodes/core/logic/15-change_spec.js +++ b/test/nodes/core/logic/15-change_spec.js @@ -1176,6 +1176,25 @@ describe('change Node', function() { }); }); + it('reports invalid fromValue', function(done) { + var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"null","fromt":"msg","to":"abc","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, + {id:"helperNode1", type:"helper", wires:[]}]; + helper.load(changeNode, flow, function() { + var changeNode1 = helper.getNode("changeNode1"); + setTimeout(function() { + var logEvents = helper.log().args.filter(function (evt) { + return evt[0].type == "change"; + }); + logEvents.should.have.length(1); + var msg = logEvents[0][0]; + msg.should.have.property('level', helper.log().ERROR); + msg.should.have.property('id', 'changeNode1'); + done(); + },25); + changeNode1.receive({payload:"",null:null}); + }); + }); + describe('env var', function() { before(function() { process.env.NR_TEST_A = 'foo'; @@ -1431,7 +1450,7 @@ describe('change Node', function() { }); }); }); - + it('applies multiple rules in order', function(done) { var flow = [{"id":"changeNode1","type":"change","wires":[["helperNode1"]], rules:[ @@ -1487,7 +1506,7 @@ describe('change Node', function() { }); }); }); - + it('can access two persistable global context property', function(done) { var flow = [{"id":"changeNode1", "z":"t1", "type":"change", "wires":[["helperNode1"]], @@ -1518,7 +1537,7 @@ describe('change Node', function() { }); }); }); - + it('can access persistable global & flow context property', function(done) { var flow = [{"id":"changeNode1", "z":"t1", "type":"change", "wires":[["helperNode1"]], @@ -1551,6 +1570,6 @@ describe('change Node', function() { }); }); }); - + }); });