An old and long on going problem with an error

I got into subflows a fair while ago. They are good.

But now and then I get an error from one, and it is confusing me.

I put in a bit of code to create an error if conditions weren't met. I'm not sure that is helping or not, but it has lead me to this question:

If an error is detected, I want to send as much information as possible to help me.

This is the relevant parts of the code which I think - for now - are important.

var device = context.get('device')||0;

and further down in the code I have:

if (ICDID != device)
    node.warn("Node Configuration not set");
    node.error("Node Configuration not set", msg)
    //  fa-eye-slash

This is the message that I receive:

{"_msgid":"935f647e.2f7718","_event":"node:4d0c9a1.2f50be4","error":{"message":"Node Configuration not set","source":{"id":"6c419eb5.eab59","type":"function","name":"Button Colour","count":1}},"time":"2020-08-13 07:40:14","topic":"ERROR_REPORT/TimePi/M C/undefined"}

Now, you can see the Node Configuration not set part. But it ends there.
(I'm suspicious I just saw the problem. But I'll continue and ask just to be sure.)

The line sends the Node configuration not set which tells me it is actually invoked for that reason. So I want to add the msg that was received to make this error.

But I'm guessing it needs to be:
node.error("Node Configuration not set" + msg)

Sure it won't actually give me much as it is forgone that ICDID != device but by this stage in the code it should be.

So I am curious what is happening to cause the error.
Maybe it is an rogue message that somehow gets into the node.

All the other needed values are protected with the || 0 at their ends.

So there is something happening but I am not getting what I expect to see.

And I right abut the + as opposed to the , for message concatenation?

Yes and no.

+ is used to join strings together.

That is not (necessarily) what you want.

If you call node.error("my error") then the error message will be logged and nothing else happens.

If you want to use a Catch node to handle the error, then you provide the msg object as the second argument to node.error - which is what you are doing.

The Catch node will use the msg you pass as the msg it sends. That msg will have its msg.error set with the details of the error.

So if you wanted to see the value of ICDID or device, then you could set them as msg properties before calling node.error...

if (ICDID != device)
    msg.device = device;
    msg.ICDID = ICDID;
    node.warn("Node Configuration not set");
    node.error("Node Configuration not set", msg)
    //  fa-eye-slash

You will then be able to inspect those values with a Debug node attached to the Catch node.

( < 7 hours sleep. Probably not good for me.)

I do have a catch node and routine dealing with that part.

That is from where I got the message I posted.
And only has the text part of node.error line.

So my thinking was I send (throw) an error and include as much as I can in the message so I can see what is going on.

I just went to look at that machine and it is now spitting out errors hand over fist.
(Not good)
Usually it happens on deploy. Not hand over fist. Setting it back to , but I know that really shouldn't make any difference.

I'll stop here as I need to look into what is happening.
And maybe let you show me (again) what I am doing wrong.

Yikes! That was really weird.

Anarchy - basically.

Changed it from + back to , in that line - ONLY - and all is now good.

So that has me stumped, as that is only invoked if the condition is met, which should be rare - if at all.
(Usually when booting and the nodes are not configured, as the name implies)