# And again more confustion about error handling

**URL:** <https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759>\
**Category:** General\
**Created:** [2 September 2018 04:12 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759 "2018-09-02T04:12:21Z")\
**Posts on this page:** 17\
**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:** [2 September 2018 04:12 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/1 "2018-09-02T04:12:21Z")

</div>

Ok, at the beginning I was silly. I didn't get all the quirks with MQTT and msg.error.

I think I have moved forward from there but "it" still doesn't seem to be working.

Though the long way, I'll start with knowns and work towards the error.  
That way it may help you see how I am confused rather than me post the real order in which things happened.

So:  
To generate an error I have this:

```auto
[{"id":"cf90dcaa.cb5a1","type":"inject","z":"98cfac7a.d84cf8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1220,"y":740,"wires":[["28da7698.4e18d2"]]},{"id":"28da7698.4e18d2","type":"function","z":"98cfac7a.d84cf8","name":"","func":"j = index.of(blah);\nreturn msg;","outputs":1,"noerr":0,"x":1400,"y":740,"wires":[[]]}]

```

It makes a nice:

```auto
"ReferenceError: index is not defined (line 1, col 5)"

```

Error in the DEBUG window.

That is in a flow with no CATCH node.

I have this code on any needed flows to catch any errors and report them back.  
Yes, some nodes need editing to give the correct names. Thought I should declare that.

So, the nodes have the right names.

```auto
[{"id":"ae688514.9c35a","type":"comment","z":"98cfac7a.d84cf8","name":"Error catching","info":"","x":130,"y":880,"wires":[]},{"id":"c542bea1.39266","type":"catch","z":"98cfac7a.d84cf8","name":"","scope":null,"x":130,"y":920,"wires":[["d08624b3.de1ca8"]]},{"id":"19adcc0e.9befbc","type":"mqtt out","z":"98cfac7a.d84cf8","name":"ERROR_REPORT","topic":"","qos":"","retain":"","broker":"af39dd36.0e8058","x":980,"y":920,"wires":[]},{"id":"e8471ea7.f7e1e8","type":"inject","z":"98cfac7a.d84cf8","name":"","topic":"","payload":"Test","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":970,"wires":[["d08624b3.de1ca8"]]},{"id":"9815e08.0b8cf2","type":"debug","z":"98cfac7a.d84cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1100,"y":970,"wires":[]},{"id":"e85a793d.fd2ee8","type":"simple-queue","z":"98cfac7a.d84cf8","name":"queue1","x":950,"y":970,"wires":[["9815e08.0b8cf2"]]},{"id":"3b7f4d56.4fd6ea","type":"change","z":"98cfac7a.d84cf8","name":"Read","rules":[{"t":"set","p":"trigger","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1010,"wires":[["e85a793d.fd2ee8"]]},{"id":"34b6685a.f54c68","type":"change","z":"98cfac7a.d84cf8","name":"Wipe","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1050,"wires":[["e85a793d.fd2ee8"]]},{"id":"c41ab019.3587d","type":"inject","z":"98cfac7a.d84cf8","name":"Wipe","topic":"","payload":" ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":140,"y":1050,"wires":[["34b6685a.f54c68"]]},{"id":"ba2e4c37.49b1a8","type":"inject","z":"98cfac7a.d84cf8","name":"Read","topic":"","payload":" ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":140,"y":1010,"wires":[["3b7f4d56.4fd6ea"]]},{"id":"d08624b3.de1ca8","type":"function","z":"98cfac7a.d84cf8","name":"Name flow","func":"msg.topic = \"Local Readings\";\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":920,"wires":[["ac65f9f0.e3fa9"]]},{"id":"ac65f9f0.e3fa9","type":"change","z":"98cfac7a.d84cf8","name":"","rules":[{"t":"set","p":"error","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":920,"wires":[["cf3a10d9.9043d","26edae58.39e532"]]},{"id":"a11384d1.34a88","type":"function","z":"98cfac7a.d84cf8","name":"Set topic","func":"var device_name =global.get('myDeviceName');\nmsg.topic =\"ERROR_REPORT/\" + device_name + \"/\" + msg.topic;\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":920,"wires":[["19adcc0e.9befbc","e85a793d.fd2ee8"]]},{"id":"4a395e4a.3fd61","type":"link in","z":"98cfac7a.d84cf8","name":"","links":["585d89f4.3fa05"],"x":705,"y":960,"wires":[["a11384d1.34a88"]]},{"id":"17fe672e.a2aed1","type":"inject","z":"98cfac7a.d84cf8","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":478,"y":830,"wires":[["cf3a10d9.9043d"]]},{"id":"8145c990.cacbf8","type":"inject","z":"98cfac7a.d84cf8","name":"","topic":"","payload":"go","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"1","x":478,"y":870,"wires":[["cf3a10d9.9043d"]]},{"id":"cf3a10d9.9043d","type":"traffic","z":"98cfac7a.d84cf8","name":"","property_allow":"payload","filter_allow":"go","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"stop","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":false,"differ":false,"x":648,"y":920,"wires":[["a11384d1.34a88"]]},{"id":"26edae58.39e532","type":"debug","z":"98cfac7a.d84cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":880,"wires":[]},{"id":"af39dd36.0e8058","type":"mqtt-broker","z":"","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"20","cleansession":true,"birthTopic":"SOM","birthQos":"2","birthPayload":"'Awaiting Music Pi'","willTopic":"EOM","willQos":"2","willPayload":"'MusicPi telemetry failure'"}]

```

Now if I put the first bit of code on THAT flow/tab, and press the inject button, I get:

```auto
local Readings : msg : Object
object
_msgid: "e0033ac7.5a9ed8"
topic: "Local Readings"
payload: 1535861136083
error: 1535861136083
_error: object
empty

```

at the first debug node.  
Pressing the READ button (inject node) I get the same at the second debug node.

I was told that MQTT doesn't handle error message when I was sending messages over it, and was shown how to get around that.  
Which is what I have done with the CHANGE node.  
But that's academic because all this is way before MQTT is used.

So what is happening to the error message?

I'll dig around too, but (as you may have guessed:) I need to ask.

Thanks.

---

<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:** [2 September 2018 04:25 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/2 "2018-09-02T04:25:01Z")

</div>

Seems I did that silly ting with the CHANGE node.

Rather than setting the msg.payload to msg.error, I was setting msg.error to msg.payload.

Reversed the names and it seems to be working a lot better.

Sorry. I shall again say that how the CHANGE node is worded is confusing as it isn't (to me) intuitive.

I know it is not as easy but I think of things that I move the first value to the second.  
But it REALLY sets the first one to the second one.

Oops.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 September 2018 06:16 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/3 "2018-09-02T06:16:00Z")

</div>

> [@Trying\_to\_learn](#):
>
> I know it is not as easy but I think of things that I move the first value to the second.

I think of it as being the same as a standard line of code :

`msg.payload = msg.error`

but written vertically

```
msg.payload
=
msg.error

```

Simon

---

<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:** [2 September 2018 06:23 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/4 "2018-09-02T06:23:09Z")

</div>

Yes, but when you go to other options (can't remember now exactly) the layout looks ok.

But to me, when I see the layout I get which is which reversed.

I just looked and now it kind of makes sense, but maybe because the threshold has been passed.

I hope I don't keep falling into that problem. But I don't often use that node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 September 2018 07:06 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/5 "2018-09-02T07:06:08Z")

</div>

> [@Trying\_to\_learn](#):
>
> I know it is not as easy but I think of things that I move the first value to the second.  
> But it REALLY sets the first one to the second one.

Are you saying that you expect  
 ![Screenshot-2018-09-02-08%3A02%3A11](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/89a4d88fafb9fdf712fcf51171e6e41c8d1bfc38.png)  
to Move msg.error to msg.payload

If so what you expect this to do?  
 ![Screenshot-2018-09-02-08%3A04%3A44](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/35585ff8df0310222adaaa766489a8f95c29f7d4.png)

---

<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:** [2 September 2018 07:19 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/6 "2018-09-02T07:19:11Z")

</div>

That's where I fall over.

In the first example, I see it as setting msg.error to msg.payload.

In the second one - which is "more intuitive" (cringing at that) is that msg.error gets MOVED to msg.payload.

But in the second one the direction of what is moved is the other way.

I think I am too confused at this point.

(Shakes head to try and clear things.)

Ok, here is what I have NOW.  
 ![Screenshot%20from%202018-09-02%2017-12-06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/24a42b904539ac4cdc889dc7b9e99be32b56ddf5.png)

I had that the other way around thinking (and reading it) that it would move msg.error TO msg.payload.

But because the SET word is used I am/was/(still am?) confused.

In your second example where you have/say MOVE msg.error. TO msg.payload that is the way it moves - or so you are saying.

All I know is that with it how it is NOW shown, it works.

I had it the other way around and it was failing because the error message wasn't getting through to the next stage.

Am I more confused? Probably. Sorry if I am waffing now, but I am still confused.

> [@cymplecy](#):
>
> msg.payload = msg.error

I think that will really help me.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 September 2018 07:24 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/7 "2018-09-02T07:24:28Z")

</div>

> [@Trying\_to\_learn](#):
>
> I think that will really help me.

🙂

I sympathise with your confusion - I thought it was just me! 🙂

Quite a few times I've struggled to debug something and its because I've done it the wrong way around

I only get it wrong when using msg properties - I'm fine when using it to set flow ones

Simon

---

<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:** [2 September 2018 07:28 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/8 "2018-09-02T07:28:38Z")

</div>

What "annoys" (or confuses?) me is that with the MOVE, it makes sense.

I MOVE _a_ to _b_.

b = a

But with SET.....

I parse it as SET _a_ to _b_ Or a = b, when it is setting b to a. (Or have I got that around the wrong way? The more I think about it the more it hurts.)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 September 2018 07:29 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/9 "2018-09-02T07:29:45Z")

</div>

> [@Trying\_to\_learn](#):
>
> But in the second one the direction of what is moved is the other way.

That is because the first one does not Move it Sets.  
I do agree that it could be improved a little. If Set changed the word before the second field, currently "to" to "from" so the Set screen read "Set msg.payload from msg.whatever" it would be less capable of misinterpretation I think. Whether that word could be made to change with the selection in the dropdown I don't know.

---

<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:** [2 September 2018 07:32 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/10 "2018-09-02T07:32:43Z")

</div>

The way to improve it would be to make the change always the same direction.

So if you say:

MOVE A -\> B

Then: B = A. (But B is negated, or what ever)

If you say SET A -\> B

Then B = A. Same Direction.

But that's just me. Keeping things the same.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 September 2018 07:35 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/11 "2018-09-02T07:35:01Z")

</div>

Forget about the change node for the moment. What would you expect to happen if I said  
Set msg.payload to 7

---

<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:** [2 September 2018 07:38 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/12 "2018-09-02T07:38:15Z")

</div>

Yes, I get it here, now.

But "SET" throws me - when used with MOVE.

SET msg.payload to 7

msg.payload = 7.

But I am getting what/where you are going.  
Just if I am silly enough to fall for it, who else could?

So when MOVE is used..... argh, I give up. (cheeky wink)

But thanks.  
I am starting to get the idea.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 September 2018 07:45 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/13 "2018-09-02T07:45:04Z")

</div>

> [@Trying\_to\_learn](#):
>
> So when MOVE is used..... argh, I give up.

Just think  
Set msg.payload to 7  
Move the dagger to the billiard room  
The difference in direction is implicit in the English language. I guess for non-English speakers it may well be even more confusing.

---

<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:** [2 September 2018 07:52 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/14 "2018-09-02T07:52:15Z")

</div>

Well, I won't argue with that at all.

Lesson learned.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [2 September 2018 12:36 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/15 "2018-09-02T12:36:36Z")

</div>

I've always said the same thing -- the fact that the "Set" option is reversed from the "Move" logic has always tripped me up.

I would love to see it changed from:

> "Set" target \<- source

to:

> "Copy" source -\> target

just as:

> "Move" source -\> target

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 September 2018 13:01 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/16 "2018-09-02T13:01:06Z")

</div>

> [@cymplecy](#):
>
> I sympathise with your confusion - I thought it was just me!

Yup, I get confused by that too. I always have to stop and think.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 September 2018 14:04 UTC](https://discourse.nodered.org/t/and-again-more-confustion-about-error-handling/2759/17 "2018-09-02T14:04:50Z")

</div>

I think everyone has that confusion, I know I do too. I like 'copy' instead of 'set'!
