# Stuck with things happening in rare conditions

**URL:** <https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132>\
**Category:** General\
**Created:** [1 July 2024 04:42 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132 "2024-07-01T04:42:23Z")\
**Posts on this page:** 9\
**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:** [1 July 2024 04:42 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/1 "2024-07-01T04:42:23Z")

</div>

Today was an example of something I don't like happening.  
But it did.

As much as that was an eye opener, it is also stumping me.

(To digress)  
I have made my own special _RBE_ nodes.  
AFAIK they work.  
Haven't seen problems with them but today threw a big spanner in the works.  
They failed - or did they?

Yeah, it isn't helping the error catching is not _RAW_ and a routine handles them.  
But it was giving me enough information that I am sure that these node are the problem.

So, back to the story:

Lots of piccies.

The error.

 ![Screenshot from 2024-07-01 13-23-13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c19041cfbf1563791bf7fcc3360b0fbb71c895b9.png)

Searching for the node.

 ![Screenshot from 2024-07-01 13-23-27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/6572d96659967c3b64805472e19ab13ee0077692.png)

What's going in to it.

 ![Screenshot from 2024-07-01 13-24-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/637987217e1dabf8a3353e2e19d8c63474fa84f8.png)

So:  
Work the problem.

On my main machine I made a flow that does the same.

(code below)

```auto
[{"id":"5a6ca5972b0f9e7b","type":"subflow","name":"Adv blocker","info":"2024 07 01\n==========\n\nTidied up code in `function` node - replaced `var` with `let`.\n\n2024 06 17\n==========\n\nDefine `TOPIC` to control how the gate filters messages.\n(All commands are all uppercase)\nYou need to set the `env` variable `TOPIC` to set the control topic.\nInput values:\n - STOP - basically don't pass ANY message.\n - ALL - pass all messages.\n - BLOCK - block repeats of same message.\n - ONE - pass ONLY the next message to arrive. (ONE)\n\nAdded error catching - may be better.","category":"","in":[{"x":170,"y":130,"wires":[{"id":"685360a3.c08db8"}]}],"out":[{"x":550,"y":130,"wires":[{"id":"685360a3.c08db8","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":""},{"name":"DEFAULT_MODE","type":"str","value":"","ui":{"label":{"en-US":"Default Mode"},"type":"select","opts":{"opts":[{"l":{"en-US":"All"},"v":"ALL"},{"l":{"en-US":"Stop"},"v":"STOP"},{"l":{"en-US":"Block"},"v":"BLOCK"},{"l":{"en-US":"One only"},"v":"ONE"}]}}},{"name":"topic_mode","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool"]}}},{"name":"msg_part_to_scan","type":"str","value":"","ui":{"label":{"en-US":"Message part"},"type":"input","opts":{"types":["str"]}}}],"meta":{},"color":"#3FADB5","icon":"node-red/function.svg","status":{"x":550,"y":190,"wires":[{"id":"197b01d950cf86b4","port":0}]}},{"id":"685360a3.c08db8","type":"function","z":"5a6ca5972b0f9e7b","name":"My blocker node. V6.3c","func":"// Version 6.3.1\n// 2024 07 01\n// Replaced `var` with `let`\n\n// Version 6.3\n// 2022 04 25\n// Added topic specific blocking or generic\n// This is mentiond below on earlier update but not applied.\n// 2023 10 03\n// Problem with control_topic fixed.\n\n// The shape property can be: ring or dot.\n// The fill property can be: red, green, yellow, blue or grey\n\n////////////////////////////////////////////////////////////////////////////////\n// 2022 04 27\n// Added env(msg_part_to_scan) to determine which part of the message is used\n// to detect repeats.\n\n\n// These are the three commands accepted.\nconst all = \"ALL\"; // Allow all message to pass\nconst block = \"BLOCK\"; // Block repeat message (of same topic)\nconst one = \"ONE\"; // Allow ONE message to pass. (may not be perfect)\nconst stop = \"STOP\"; // Block ALL message... ALL!\n\nlet previousMode;\nlet newval;\n\n// Get topic. Set to `BLANK` if nothing else.\nlet topic = msg.topic;\nif (topic == \"\")\n topic = \"BLANK\";\nif (topic == null)\n topic = \"BLANK\";\nif (msg.topic == undefined)\n topic = \"BLANK\";\n\n////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////\n// Get all `env` letiables working here.\n// Get which part of the message to use.\n\n// Get the topic used to determine which messages are to control the mode.\nlet CTLTopic = env.get(\"TOPIC\");\nif (CTLTopic.length < 1)\n throw \"You must define a TOPIC for controlling the node\";\n//------------------\n\n// Get which part of the message is to be used.\nconst part = env.get(\"msg_part_to_scan\");\nif (part.length < 1)\n throw \"You must define which part of the message to scan\";\n// Set `newval` from incoming message.\n//newval = msg[part]; // Extract the desired part of the message.\nnewval = RED.util.getMessageProperty(msg,part); // Extract the desired part of the message.\n//------------------\n\n// Get the topic_mode. This means that the msg.topic is used in filtering if `true`.\nlet topic_mode = env.get(\"topic_mode\");\nif (topic_mode.length < 1) // If it is not set...\n topic_mode = \"false\";\nif (topic_mode == \"false\")\n topic = \"BLANK\"; // Set to \"BLANK\" to give it at least a constant topic.\n//------------------\n\n// Error is `MODE` is not set.\nlet mode = context.get(\"MODE\");\nif (mode.length < 1)\n throw \"You must set a MODE: ALL, STOP, BLOCK or ONE\";\n//------------------\n\n\n\n//&&//&&//&&//&&//&& End of setup\n\n\n\n\n////////////////////////////////////////////////////////////////////////////////\n// Change node's MODE.\nif (msg.topic == CTLTopic) {\n //\n // Set how node works.\n //\n\n if (msg.payload == stop) {\n node.status({ text: \"Set to stop\" });\n context.set(\"MODE\", msg.payload);\n node.warn(\"Set to STOP\");\n } else if (msg.payload == block) {\n node.status({ text: \"Set to block\" });\n context.set(\"MODE\", msg.payload);\n node.warn(\"Set to BLOCK\");\n } else if (msg.payload == all) {\n node.status({ text: \"Set to allow\" });\n context.set(\"MODE\", msg.payload);\n node.warn(\"Set to ALL\");\n } else if (msg.payload == one) {\n // context.set(\"previousMode\",context.get(\"MODE\"));\n context.set(\"previousMode\", mode);\n // node.warn(\"132 Previous mode \" + context.get(\"MODE\"));\n node.status({ text: \"Set to one\" });\n context.set(\"MODE\", msg.payload);\n mode = context.get(\"MODE\");\n }\n return;\n}\n////////////////////////////////////////////////////////////////////////////////\n\n\n// Used to determine if a message was received to change the mode.\nlet updated_mode = context.get(\"updated_mode\") || 0;\n\n// Get the previous stored value.\nlet lastval = context.get(topic);\n\n\n// -- Main code starts here.\n\n// =============== STOP\nif (mode == stop) {\n return;\n}\n// =============== ALL\nelse if (mode == all) {\n node.status({ fill: \"blue\", shape: \"dot\", text: \"All\" });\n context.set(topic, newval);\n return msg;\n}\n// =============== BLOCK\nelse if (mode == block) {\n //\n // See if the new value is different to the old value.\n //\n if (newval != lastval) {\n context.set(topic, newval);\n node.status({ fill: \"green\", shape: \"dot\", text: \"Passed\" });\n return msg;\n }\n node.status({ fill: \"red\", shape: \"dot\", text: \"Blocked\" });\n return;\n}\n// =============== ONE\nelse if (mode == one) {\n //\n // Allow only 1 message to pass\n //\n // mode = context.get(\"MODE\");\n previousMode = context.get(\"previousMode\");\n // context.set(\"MODE\",context.get(\"previousMode\"));\n context.set(\"MODE\", previousMode);\n context.set(topic, newval);\n //\n node.status({ text: \"Set to \" + previousMode });\n return msg;\n}\n","outputs":1,"timeout":"","noerr":0,"initialize":"let default_mode = env.get(\"DEFAULT_MODE\");\ncontext.set(\"MODE\", default_mode);\nnode.status({ text:default_mode });","finalize":"","libs":[],"x":360,"y":130,"wires":[[]]},{"id":"197b01d950cf86b4","type":"status","z":"5a6ca5972b0f9e7b","name":"","scope":["685360a3.c08db8"],"x":310,"y":190,"wires":[[]]},{"id":"a1f2cad54a9a24b1","type":"catch","z":"5a6ca5972b0f9e7b","name":"","scope":["685360a3.c08db8"],"uncaught":false,"x":320,"y":240,"wires":[["9b815fe0cfb88e40"]]},{"id":"9b815fe0cfb88e40","type":"function","z":"5a6ca5972b0f9e7b","name":"Upsend error message","func":"const id = env.get(\"NR_NODE_PATH\");\nconst ids = id.split(\"/\");\nconst errr = `Something went wrong in subflow (See source number below).\\nopen the _error.source object (below) to get more details`;\nmsg.source = ids[1];\nnode.error(errr, msg);\n \n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":240,"wires":[[]]},{"id":"7bc21e6578052640","type":"function","z":"d65ab744.465758","name":"function 56","func":"msg = {\"payload\":\"Offline\",\"topic\":\"1.144.25.184\",\"_msgid\":\"99c94b6499d64b62\",\"device\":\"UpLink\",\"IP\":\"1.144.25.184\",\"_event\":\"node:ca7b2a2f.da6688\"}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":1760,"wires":[["9883153d1bbb687d"]]},{"id":"0cde48fcad47998d","type":"inject","z":"d65ab744.465758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":1760,"wires":[["7bc21e6578052640"]]},{"id":"9883153d1bbb687d","type":"subflow:5a6ca5972b0f9e7b","z":"d65ab744.465758","name":"","env":[{"name":"TOPIC","value":"MODE","type":"str"},{"name":"DEFAULT_MODE","value":"ALL","type":"str"},{"name":"msg_part_to_scan","value":"payload","type":"str"}],"x":650,"y":1760,"wires":[["f2e39c2f0ed71175"]]},{"id":"47615e8b9b5ed5c0","type":"function","z":"d65ab744.465758","name":"function 57","func":"msg = {\"payload\":\"1.144.25.184\",\n \"topic\":\"1.144.25.184\",\n \"device\":\"UpLink\",\n \"IP\":\"1.144.25.184\",\n \"_event\":\"node:99f3baf.756be48\",\n \"filename\":\"/home/pi/.node-red/public/uplink.txt\"}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":1820,"wires":[["9883153d1bbb687d"]]},{"id":"cdb430dcc2c4f89a","type":"inject","z":"d65ab744.465758","name":"BLOCK","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MODE","payload":"BLOCK","payloadType":"str","x":490,"y":1630,"wires":[["9883153d1bbb687d"]]},{"id":"c3d3c4280707c5c0","type":"inject","z":"d65ab744.465758","name":"ALL","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MODE","payload":"ALL","payloadType":"str","x":490,"y":1660,"wires":[["9883153d1bbb687d"]]},{"id":"33678f1f777e371f","type":"inject","z":"d65ab744.465758","name":"STOP","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MODE","payload":"STOP","payloadType":"str","x":490,"y":1690,"wires":[["9883153d1bbb687d"]]},{"id":"76e48f9f6cb39de8","type":"inject","z":"d65ab744.465758","name":"ONE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MODE","payload":"ONE","payloadType":"str","x":490,"y":1720,"wires":[["9883153d1bbb687d"]]},{"id":"f2e39c2f0ed71175","type":"debug","z":"d65ab744.465758","name":"debug 2537","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":840,"y":1760,"wires":[]},{"id":"f0cfc9d0a0689a8c","type":"inject","z":"d65ab744.465758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":1820,"wires":[["47615e8b9b5ed5c0"]]}]

```

 ![Screenshot from 2024-07-01 14-36-46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85be37cd73d487e95699503c51436e6edddb02ff.png)

# Setting the node to `ALL` or `BLOCK` makes no difference. NO ERRORS happen.

It works fine.

Yeah, ok. NR versions?

Faulty machine:  
3.0.2  
Working machine  
3.1.5

Node versions:  
Faulty machine,  
Working machine,  
Same:  
`16.20.2`

Ok, I shall do tests on the _Faulty_ machine - and that is not fair on it, as I am not sure it is. But for the sake of distinguishing the two.....

There is a SUBFLOW (yeah, sorry) but it isn't rocket science what it does.  
It is just a slightly tweaked controllable that either lets messages through, blocks repeats, lets only ONE through or blocks all.

I'm stuck how to track down the problem.

Anyone?

And yes, I've stuck debug nodes all over the place, but it is kinda difficult on the _faulty_ machine when it is LIVE and doing a lot more other stuff to diagnose the problem.

# UPDATE

I copied that example flow into a _spare_ page/tab on the _faulty_ machine.

It works.

So, now it raises the question:  
**WHAT'S GOING ON** with the `msg.payload` I copied from the (as best I could get) source?  
(Third picture)

Ok, it may not be THAT message, but what goes in wasn't changing.  
Just it was not the usual message when my _UPLINK_ is working.

# P.S.

Could/would _you_ mind checking the `subflow` that it is sending the correct information up to the parent flow?  
that is done in the `upsend error message` `function` node that is connected to the `catch` node in the `subflow`.  
As, if it is not giving me the right information, that's probably half/most of the problem.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [1 July 2024 05:50 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/2 "2024-07-01T05:50:56Z")

</div>

At a click glance, the first error message is hinting at the issue. You have a null or undefined variable that you are trying to convert to an object.

You know the drill by now. Lots of debug (or other debugging) nodes prior to the error being generated. If you have subflows, pull out all the nodes and run in a non-subflow environment for better visualisation of the issue.

If this happens rarely then it is probably an edge-case. You need to generate some test data to feed in based on your observations of when the error occurs (eg at startup etc).

Then, problem solved!

Good luck.

---

<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:** [1 July 2024 05:57 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/3 "2024-07-01T05:57:09Z")

</div>

Thanks @Bobo I want to make sure that the message is a true reflection of the problem.

I'm saying that because the _normal_ message going through and the one which gives an error have the same _structure_ to the best of what I can see.

So if they have that, then the error message can't be correct.

I guess I could disable the `catch` node in the `subflow` and see what happens.

The only _problem_ is the cause of the problem.  
And how to recreate it.

_Scratches head. May have to think WAY outside the box for this one._

---

<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:** [1 July 2024 06:58 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/4 "2024-07-01T06:58:45Z")

</div>

# (If you've got this far)

In the `subflow` I have this code:

```auto
const id = env.get("NR_NODE_PATH");
const ids = id.split("/");
const errr = `Something went wrong in subflow (See source number below).\nopen the _error.source object (below) to get more details`;
msg.source = ids[1];
node.error(errr, msg);

```

Given that all the `env` things are set, is this the right code to _onsend_ the correct information so what is _wrong_ is correctly reported when the main/parent flow received the error?

The message tells me to look at another part of the error to get the number of the `subflow` so I know WHICH ONE got the error.  
(as it is used quite a lot of times)

And it would be good if I get the right/correct details.  
Getting the wrong details would not help me finding the error.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [1 July 2024 10:16 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/5 "2024-07-01T10:16:50Z")

</div>

Just remember the golden rule of programming ... The more complicated your code, the more effort required to debug and maintain it. Keep it Simple.

---

<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:** [1 July 2024 10:23 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/6 "2024-07-01T10:23:30Z")

</div>

And this seems beyond me.

And so I am asking for help making sure I am not missing anything

# OR

Sending myself a corrupt error message.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [1 July 2024 10:26 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/7 "2024-07-01T10:26:08Z")

</div>

My rates are $1250 AUD per day 😝

---

<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:** [1 July 2024 10:26 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/8 "2024-07-01T10:26:43Z")

</div>

_Checks in the mail_

😉

---

<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:** [29 September 2024 10:26 UTC](https://discourse.nodered.org/t/stuck-with-things-happening-in-rare-conditions/89132/9 "2024-09-29T10:26:47Z")

</div>

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