# An old and long on going problem with an error

**URL:** <https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501>\
**Category:** General\
**Created:** [12 August 2020 22:05 UTC](https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501 "2020-08-12T22:05:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2020 22:05 UTC](https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501/1 "2020-08-12T22:05:25Z")

</div>

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.

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

```

and further down in the code I have:

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

```

This is the message that I receive:

```auto
{"_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?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 August 2020 22:18 UTC](https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501/2 "2020-08-12T22:18:45Z")

</div>

> [@Trying\_to\_learn](#):
>
> 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...

```auto
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
    return;
}

```

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2020 22:26 UTC](https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501/3 "2020-08-12T22:26:22Z")

</div>

( \< 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.  
😉

Update:  
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)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 October 2020 22:26 UTC](https://discourse.nodered.org/t/an-old-and-long-on-going-problem-with-an-error/31501/4 "2020-10-11T22:26:32Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
