Help with subflow error detection

Sorry folks, but I'm stuck what to do.

Problem:
A subflow gives an error and I can't search for which subflow made the error.

It's a given that an error will happen as the code in the subflow ONLY creates errors.

But what you see in the debug window (right side) doesn't help me know which subflow caused it.

Options?

Add a Change node after the Catch node that adds something into the message that tells you which one it is.

Sorry how will adding a change node (outside the subflow) help me determine which node in the subflow is causing the error?

You asked:

You didn't asked which node was it.

Yeah, ok... But still, saying I want to identify which subflow.....

How can putting the change node OUTSIDE the subflow work?
There are MANY subflows on many tabs. Some used on all tabs.

How would what you suggest help in this situation?

Use different catch nodes for each subflow.

1 Like

The error msg gives you an id .. did you search for that id ?
seems to be coming from a Function node ?

image

I didn't know you could put catch nodes in subflows.

(If you can, could you show me how? Where would the output of the node go?)

@UnborN
This is an example.

To re-state the problem:
I have MULTIPLE subflows on a machine.
They are used (or could be used) multiple times on several tabs.

The other day I got a message after a machine was rebooted.

Searching the id from the error message yielded NOTHING.

So I'm guessing the offending node is in a subflow.

WHICH ONE?
As in which subflow. The specific instance is neither here nor there.
But as is there is no way to track down the error.

Putting a change node in the main flow after the catch node would be pointless - unless I am missing something. In which case please be specific and not beating around the bush.

Luckily it isn't Life or Death but it is annoying.

As I don't even know WHICH subflow it is, I can't really do much.

Taking that a different way:
So you want me to put a catch node for every subflow?
So.... on some machines that would be..... 30 or so at least.

you are right .. we cant search that id

Did a quick test of a subflow (with a nested Function node that throws an error)
and the error id doesnt match of that of the Function
i thought it would .. hence my suggestion

you have an indication with the Function's name though ..
"This will throw an error" .. funny .. you toying with us ? :wink:

image

it doesn't need to be in the subflow .. but as Colin said you'll need a Catch node for each subflow
and each Catch node only to be linked to individual Subflow

So to catch this "one off on reboot" I have to populate my flow with ..... 70 or so catch nodes.

Yeah, I'll let this go to the keeper. Reward for time is too low.

Yes, the "This will throw an error" is a specific bit of code I use to test my error catching routine and for the sake of making the example easily detectable, I did name the node as shown.

Just to share and maybe help others, this is my routine (subflow in it) that I put on most/all tabs.

There are external things set which are used to identify the flow.

[{"id":"62be7566.4b4454","type":"subflow","name":"Error catch","info":"","category":"","in":[{"x":120,"y":250,"wires":[{"id":"1b99b8b4.ecf75f"}]}],"out":[{"x":1040,"y":280,"wires":[{"id":"a142130.032a0f","port":0}]},{"x":1040,"y":330,"wires":[{"id":"f632883f.7b7a28","port":0}]}],"env":[],"color":"#DD0000","outputLabels":["Error output","Overspeed alarm"],"icon":"node-red/alert.svg","status":{"x":1040,"y":390,"wires":[{"id":"101bf1bb.1f7d56","port":0}]}},{"id":"ab7353b2.d1b098","type":"msg-speed","z":"62be7566.4b4454","name":"Speed check","frequency":"sec","estimation":false,"ignore":false,"x":450,"y":330,"wires":[["c7fad2ac.ec77e"],[]]},{"id":"c7fad2ac.ec77e","type":"switch","z":"62be7566.4b4454","name":"> max_speed?","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"max_speed","vt":"global"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":330,"wires":[["f632883f.7b7a28"]]},{"id":"f632883f.7b7a28","type":"change","z":"62be7566.4b4454","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":330,"wires":[["a142130.032a0f","101bf1bb.1f7d56"]]},{"id":"a142130.032a0f","type":"gate","z":"62be7566.4b4454","name":"","controlTopic":"control","defaultState":"open","openCmd":"go","closeCmd":"stop","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":920,"y":280,"wires":[[]]},{"id":"45c23f97.247a68","type":"change","z":"62be7566.4b4454","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"error","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":280,"wires":[["d9bab478.78eb8"]]},{"id":"1b99b8b4.ecf75f","type":"switch","z":"62be7566.4b4454","name":"RESET?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"RESET","vt":"str"},{"t":"neq","v":"RESET","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":250,"wires":[["7eb12133.460c6"],["ab7353b2.d1b098","30576976.5a4d76"]]},{"id":"7eb12133.460c6","type":"change","z":"62be7566.4b4454","name":"Go","rules":[{"t":"set","p":"payload","pt":"msg","to":"go","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":190,"wires":[["a142130.032a0f","101bf1bb.1f7d56"]]},{"id":"101bf1bb.1f7d56","type":"function","z":"62be7566.4b4454","name":"","func":"if (msg.payload == \"stop\")\n{\n    msg.payload = ({fill: \"red\",text:\"Overspeed\"});\n}\nif (msg.payload == \"go\")\n{\n    msg.payload = ({fill: \"green\",text:\"Good\"});\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":930,"y":390,"wires":[[]]},{"id":"dc4e7681.85bec8","type":"moment","z":"62be7566.4b4454","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD HH:mm:ss","locale":"en_AU","output":"payload","outputType":"msg","outTz":"Australia/Sydney","x":745,"y":230,"wires":[["b6239445.5a3bb"]],"l":false},{"id":"b6239445.5a3bb","type":"change","z":"62be7566.4b4454","name":"Time","rules":[{"t":"move","p":"payload","pt":"msg","to":"time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":230,"wires":[["b8ab3ac7.6b4788"]]},{"id":"30576976.5a4d76","type":"change","z":"62be7566.4b4454","name":"Save","rules":[{"t":"set","p":"payload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":230,"wires":[["372932c7.1c595e"]]},{"id":"b8ab3ac7.6b4788","type":"change","z":"62be7566.4b4454","name":"Get","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":280,"wires":[["45c23f97.247a68"]]},{"id":"372932c7.1c595e","type":"change","z":"62be7566.4b4454","name":"TimeStamp","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":230,"wires":[["dc4e7681.85bec8"]]},{"id":"d9bab478.78eb8","type":"function","z":"62be7566.4b4454","name":"Get name/s","func":"//var flow_name = flow.get(\"$parent.name\");\n//return msg;\n\nvar device_name =global.get('myDeviceName');\nvar flow_name = flow.get(\"$parent.name\");\nmsg.topic =\"ERROR_REPORT/\" + device_name + \"/\" + flow_name;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":745,"y":280,"wires":[["a142130.032a0f"]],"l":false},{"id":"aa78ace9.fb58","type":"inject","z":"aa48e352.9ad2f8","name":"Reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"RESET","payload":"","payloadType":"date","x":3710,"y":230,"wires":[["a5b8b147.602cd"]]},{"id":"a5b8b147.602cd","type":"subflow:62be7566.4b4454","z":"aa48e352.9ad2f8","name":"","x":3910,"y":200,"wires":[["c8e77e13.fe80b","5a4619d.343b0e8"],["786991bf.44a08"]]},{"id":"786991bf.44a08","type":"link out","z":"aa48e352.9ad2f8","name":"Runaway","links":["8da8c919.68c64","71f2396c.bae758","790c18ae.de419"],"x":4090,"y":230,"wires":[],"l":true},{"id":"1d24f9c6.5e269e","type":"catch","z":"aa48e352.9ad2f8","name":"","scope":null,"x":3700,"y":180,"wires":[["a5b8b147.602cd"]]},{"id":"2959e713.3ff1a8","type":"inject","z":"aa48e352.9ad2f8","name":"RESET","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"reset","payloadType":"str","x":3890,"y":310,"wires":[["5a4619d.343b0e8"]],"icon":"font-awesome/fa-eject"},{"id":"b9166288.3410d8","type":"inject","z":"aa48e352.9ad2f8","name":"Next","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"trigger","payloadType":"str","x":3890,"y":270,"wires":[["5a4619d.343b0e8"]],"icon":"node-red/trigger.svg"},{"id":"5a4619d.343b0e8","type":"q-gate","z":"aa48e352.9ad2f8","name":"qgate","controlTopic":"CONTROL","defaultState":"queueing","openCmd":"Go","closeCmd":"Stop","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"50","keepNewest":true,"qToggle":false,"persist":false,"x":4080,"y":270,"wires":[["e552f4d2.7ddcb"]]},{"id":"e552f4d2.7ddcb","type":"debug","z":"aa48e352.9ad2f8","name":"Machine health error list","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":4290,"y":270,"wires":[]}]

ok .. and this Function is in a Subflow
and you have 70 instances of the same Subflow ?

if it always happens on reboot .. maybe you could disable parts or whole Flows to cut the problem down

In THIS example: yes.
(Where I created the error to demonstrate the problem)

In Reality: I don't know what node is causing the problem.
Other than it is from one of many subflows.

I'm moving on. Too much time spent on this and it isn't getting me anywhere.

Its an interesting problem ..

there is an alternative that i just tested ..
do the opposite .. DONT use Catch nodes and let it throw an error!
and hover over the Error msg (or double click it) and that will indicate what Subflow created it

.. and once you know what msg and subflow threw it .. do better handling so it doesnt happen

I will probably have to do that for now.

Considering I know SFA about javascript and the like.....

same here .. learning too .. much from your posts

If you going the Javascript path then look into using a try catch code block
lets say you have a Function and all you know is that it "may throw an error" (jk) at some point
add its logic into a try catch block and handle the error the way you want

Example Flow

[{"id":"249b35248bafa4e5","type":"subflow","name":"Subflow 1","info":"","in":[{"x":60,"y":80,"wires":[{"id":"98b5654cb92a28bf"}]}],"out":[{"x":340,"y":80,"wires":[{"id":"98b5654cb92a28bf","port":0}]}]},{"id":"98b5654cb92a28bf","type":"function","z":"249b35248bafa4e5","name":"","func":"try {\n    if (msg.payload === 0) {\n        throw new Error(\"Division with 0\")\n    }\n    else {\n        msg.payload = 100 / msg.payload\n        return msg;\n    }\n\n} catch (error) {\n    node.error({\n        err: error.toString(),\n        path: node.path\n    });\n};\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":80,"wires":[[]]},{"id":"1e1a03c34b5cb1ea","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":370,"y":560,"wires":[["28e6cec63f859578"]]},{"id":"512bf5b8411fa155","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":640,"wires":[]},{"id":"28e6cec63f859578","type":"subflow:249b35248bafa4e5","z":"54efb553244c241f","name":"","x":560,"y":640,"wires":[["512bf5b8411fa155"]]},{"id":"120c580756d7c9ab","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":370,"y":640,"wires":[["28e6cec63f859578"]]},{"id":"34ea84f8f5c15d3d","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":370,"y":720,"wires":[["28e6cec63f859578"]]},{"id":"7d1a7f458ddda6f4","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":370,"y":820,"wires":[["a759eea439131a96"]]},{"id":"3c04342414aa88e4","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":900,"wires":[]},{"id":"a759eea439131a96","type":"subflow:249b35248bafa4e5","z":"54efb553244c241f","name":"","x":560,"y":900,"wires":[["3c04342414aa88e4"]]},{"id":"6bd8c182b52d8423","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":370,"y":900,"wires":[["a759eea439131a96"]]},{"id":"997577ae273bf091","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":370,"y":980,"wires":[["a759eea439131a96"]]}]

I had a quick look at your code, but....
I fear we are not on the same page, sorry.

Your example is a given node that will error in a subflow.

I don't know which node will fail in my subflows.

All information sent to the catch node is processed by my code and there is nothing to point to the offending subflow name.

Look back at my 10'th post.
It has the code I use to parse the output of the catch node.

Rather than posting the whole flow and subflows, etc.....

How about just post the lines of Javascript I need to use to get/gleam the desired information.

You presumably already know which flow tab it is on, from which Catch node it is. Do you have 70 subflows on one flow tab?

ok .. back to the drawing board

Give all your functions or nodes unique names.
Use a Catch node inside the Subflow wired to output 2

The bottom output will be used for error reporting which will help identify where the error came from.

image

The error name will identify the nested node

image

Modified Test flow:

[{"id":"249b35248bafa4e5","type":"subflow","name":"Subflow 1","info":"","in":[{"x":60,"y":80,"wires":[{"id":"98b5654cb92a28bf"}]}],"out":[{"x":680,"y":80,"wires":[{"id":"db59b3d2f9a12a87","port":0}]},{"x":460,"y":200,"wires":[{"id":"8425f5b73bf14a4b","port":0}]}]},{"id":"98b5654cb92a28bf","type":"function","z":"249b35248bafa4e5","name":"function1","func":"\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":80,"wires":[["0a1157dc614dd892"]]},{"id":"8425f5b73bf14a4b","type":"catch","z":"249b35248bafa4e5","name":"","scope":null,"uncaught":false,"x":340,"y":200,"wires":[[]]},{"id":"0a1157dc614dd892","type":"function","z":"249b35248bafa4e5","name":"function2","func":"\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":80,"wires":[["db59b3d2f9a12a87"]]},{"id":"db59b3d2f9a12a87","type":"function","z":"249b35248bafa4e5","name":"function3","func":"msg.payload = 100 + msg.x.y  // error\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":80,"wires":[[]]},{"id":"1e1a03c34b5cb1ea","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":450,"y":620,"wires":[["28e6cec63f859578"]]},{"id":"512bf5b8411fa155","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":660,"wires":[]},{"id":"28e6cec63f859578","type":"subflow:249b35248bafa4e5","z":"54efb553244c241f","name":"","x":640,"y":700,"wires":[["512bf5b8411fa155"],["22dc0883da0db9c8"]]},{"id":"120c580756d7c9ab","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":450,"y":700,"wires":[["28e6cec63f859578"]]},{"id":"34ea84f8f5c15d3d","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":450,"y":780,"wires":[["28e6cec63f859578"]]},{"id":"7d1a7f458ddda6f4","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":450,"y":880,"wires":[["a759eea439131a96"]]},{"id":"3c04342414aa88e4","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":940,"wires":[]},{"id":"a759eea439131a96","type":"subflow:249b35248bafa4e5","z":"54efb553244c241f","name":"","x":640,"y":960,"wires":[["3c04342414aa88e4"],["f20ce4e2590a1ad3"]]},{"id":"6bd8c182b52d8423","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":450,"y":960,"wires":[["a759eea439131a96"]]},{"id":"997577ae273bf091","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":450,"y":1040,"wires":[["a759eea439131a96"]]},{"id":"22dc0883da0db9c8","type":"debug","z":"54efb553244c241f","name":"error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":720,"wires":[]},{"id":"f20ce4e2590a1ad3","type":"debug","z":"54efb553244c241f","name":"error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":1000,"wires":[]}]

No, but I would say the entire flow would have 70 subflows in/on it.

That is irrelevant. If you already have a catch node on each tab then you know which tab it is.