Why is this working in one function and not another?

I want to check my lap-top's battery using one NR-node (node-red-contrib-battery), acpi and upower (using exec-node) and get the data as graphs.

So far so good. But I also wanted to have different colour on the line depending on state (charging/discharging). Here I found some good help in how to Change line colour dependent on value

And no problem when calling acpi, but in the two others, basically the same function just give "TypeError: Cannot convert undefined or null to object"

Here are the functions, except differnt names on constants etc, due to differnt names from function it's basically the same, and can't understand the problem. Changing msg.payload to any other value than null results in no error, but why will it accept payload: null in one instance but not the others?

Here are the code as is now, I have tried so many things so hope someone have better eyes than I have now.

result from acpi, works like a charm

msg.payload = Number(msg.payload);
const charging = flow.get("charging");
let msg2 = null;

if (charging == "Charging"){
    msg.topic = "Charging";
    msg2 = {payload: null, topic: "Discharging"};
}else{
     msg.topic = "Discharging";
     msg2 = {payload: null, topic: "Charging"};
}

return [[msg2, msg]];

from the Battery node:

const charging = flow.get("isCharging");
let msg2 = null;

if (charging == true){
    msg.topic = "Charging";
    msg2 = { payload: null, topic: "Discharging"};
}else{
     msg.topic = "Discharging";
     msg2 = {payload: null, topic: "Charging"};
}

return [[msg2, msg]];

and from upower:

msg.payload = Number(msg.payload);

const charging = flow.get("state");
let msg2 = null;

if (charging == "charging"){
    msg.topic = "Charging";
    msg2 = { payload: null, topic: 'Discharging' };
}else{
     msg.topic = "Discharging";
     msg2 = {payload: null, topic: 'Charging'};
}


return [[msg2, msg]];

It may help if you also include the error you get.

As I said, only "TypeError: Cannot convert undefined or null to object"

The same result if I use the catch-node as well. Also the same in the log...

Is it relevant that in one of your snippets of code you have
if (charging == "charging"){ (lower case c)
and in another you have
if (charging == "Charging"){ (upper case C) ?

Does it make any difference if you give your constant "charging" a default value?

const charging = flow.get("state") ?? "No value"

It is always easier to understand what's going on if we can see any error message in context, ie a screen capture. Even if the screen capture shows a message letter for letter the same as you typed, it can be helpful to see it.