Search code examples
debuggingnode-red

Boolean mistake with Javascript


Having this code :

function checkIsNotOverHeating(context, surchauffe, offset, topic, node){
    let msg = null;
    let overheating;

    overheating = false;

    if(checkTemperatureWithOffset(context.get("temperatureInt"), offset, surchauffe, "-") === 1){
        // Overheating
        overheating = true;
        msg = createMessageOverheat(topic);
    }

    node.error(overheating)
    if(context.get("overheating") !== overheating) context.set("overheating", overheating);

    return msg;
}

Every node.error will output in Node the value in parameter. I'm not able to understand why, but it will accept the boolean true, and not the false, as you can see in this picture :

enter image description here

I'm using NodeRED, and as you can see, the code is simple. My function is triggered everytime.

EDIT : Don't take care of the -1, it will just shown me the variation of 2 value


Solution

  • This looks like a bug in the node.error() code as a work around try this:

    node.error(' ' + overheating);
    

    EDIT:

    Fix for this has been submitted:

    https://github.com/node-red/node-red/pull/1037