Trying to track down an error in a function node

A Catch node will only catch errors that the node developer has handled in that way. If the developer has not done that they will not be caught by a Catch node.

It is very easy to tell RTFM :wink:
If you ask me that you want to reach the moon, I will tell you the same :slight_smile:
I have already seen this node.error in the documentation, but I cannot see any examples that show how to use it...so if you make me an example inside my code or you send me a link where there are some examples, I will be more than grateful.
The other point is where this console or system log is placed . Honestly speaking I do not have any idea.
If I go in the node red log, the information is useless.


The other thing is that you can see a list of events in the mentioned log of the last hour or probably less in my case....so it does not help me, if this is the log we are speaking for.

I take a look on this too, it seems it could help, but I need to read more....also here if there are any examples, it could be useful to understand how to use it.

The best thing would be, after catching the error to save the msg object to a file again....only in this way it will be very useful and you will have the possibility to catch all the errors generated by a function or flow.

It shows you in Writing Functions : Node-RED

Sorry to tell that, but I cannot find any useful examples...or probably I am not smart enough to understand the examples and apply them in the right way. I put the following two lines in my switch case function, before the return msg :


This is the result after the flow is triggered :

As you can see, the same object has been shown in the debug panel for both warn and error.....and frankly speaking there is no any errors in the node. So it seems that there are not any differences between node.warn or node.error, it does not filter an only "warning" or an "error";
The other thing is, following what [ralphwetzel] has told, this is an event coming from the mqtt which it is not managed in my switch case function and it probably causes the error to the next node "check status light". I do not know if I can put any node.error in a current state node, but in any case, this will not been enough to trace the error, I think.
There is a need of a debug of the entire flow, so when an error occurs, to have the possibility to start from the node which the error stopped the execution and to have the possibility to look at the data generated from the previous nodes.

So, it would be ok, something similar to frogger, but with the possibility to output only the errors to the log file.
Any other ideas are welcome.

The section Handling errors in the page I linked to has:

To trigger a Catch node on the same tab, the function should call node.error with the original message as a second argument:

node.error("hit an error", msg);

With that you can Catch the error in the catch node and then do whatever is appropriate with it.

I have written a whole routine for catching and storing errors.

It is a bit of a mess, but it does what I want/need.

It has foreign nodes in it which may not be nice for some people.

(foreign nodes: non-standard)

It also needs a bit of configuration with flow.context but not that bad.

I can post it if you want, but no promises it will SOLVE your problem,
only help you catch it.

1 Like

Those logging issues are Home Assistant problems, not node-red. Not sure how HA configures things and whether the actual node-red log is available. You might have to do a manual search though your syslog.

I looked at some youtube videos, and I have understood how the catch node works...only after I see your answer...anyway, thank you very much.

Here what I have done :


I have put a noder.error("some error",msg) in all the places in which the it could arise the error. Afterwards I defined the catch node properly and I connect it to the frogger node setting the log level to error(yes it is only a text, but the messages were already filtered by the catch node). Finally it produced the result I wanted and I found the problem.

1 Like

Did you actually try searching the node-red log for error? That should have found it without having to do all that.
Also, if all you were trying to do was to see what the input to that function node was when it didn't match your expected contents then you could have sent a message to a second output on the function node when that happened, and fed that into flogger.

I am not sure where is it the node-red log...
Are you speaking for this? https://global.discourse-cdn.com/business6/uploads/nodered/original/3X/2/4/249341af4bbd0200dcdbfad49aeb6c28ce25b817.png

That doesn't look like the node-red log. It should start with a Welcome to Node-RED message. I have no idea where the log is when running with HA, but I consider that knowing how to access it is essential when using node-red.

I've made a fast research on the net for the node red log on HA. Probably the only thing is what I have already shown, and it does not give any useful information, unfortunately. Until now, I used only the debug window and since yesterday the combos node.error-catch-frogge which I suppose to be a good alternative...

Yet another reason not to use HA.

Unfortunately all my smart devices are connected with HA....do you have any alternatives in mind?

Yes, do like most here do which is to use node-red without HA.

I'm not entirely sure I'm following the problem, but I've found the Catch node to be enormously helpful in troubleshooting. And in one case where errors were normal (timeouts on SNMP responses over unreliable links), catch helped stop the syslog from filling up.

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