Catch node not finding error

I have a i2c node which monitors a the state of a battery's charge in one of my flows it works fine however if I disconnect the battery, as expected I get an error:

raspberrypi Node-RED[340]: 7 Jan 15:23:28 - [error] [i2c in:Batt %] Error: , Remote I/O error

I want to catch that error and prevent the inject node from activating the flow with i2c node in it, but the catch node does not catch the error, I set the catch node to catch all and also tried catching error from the i2c node generating the error but I get nothing on the catch node output.

why ? is there something i am missing ?

I also tried a status node pointing at the i2c node but I just get the following whether theirs a error or not.

object
status: object
source: object
id: "ee9238a9.5db1b8"
type: "i2c in"
name: "Batt %"
_msgid: "4b141956.7424c8"

please advise thanks

  1. where do you see that error? in the debug sidebar?
  2. is the catch node on the same tab?
  3. did you try selecting - in the catch node, the i2c node?
  1. yes in the side bar & on the console
  2. yes same tab ( its a separate tab with just the one flow)
  3. yes tried catch all and also just the i2c node

Hi @Dave

the Catch node is only able to catch errors that have been logged in a particular way by the node.

Assuming you are using node-red-contrib-i2c, you can see how it logs errors in the file here: https://github.com/nielsnl68/node-red-contrib-i2c/blob/master/i2c/26-i2c.js

If you search for node.error in that file you will see in some places the node calls it with one argument, and in some cases with two. The Catch node will only handle the calls to node.error() with two arguments - as the second argument is the message object for the Catch node.

Without a fix to the node, you won't be able to handle those errors in your flow.

OK fixed that and it now works thanks for your help.

Wasn't the Solution provided by knolleary in post #4?

solved

oh looks like I got caught by the solution police, well I was just confirming that the suggested fix by knolleary in post #4 was actually the solution to issue raised and as he didn't mark his post as the solution I thought it was appropriate that I did to close off the post.

Clearly you think that its not appropriate, but to be honest I don't care, because the fix kindly offered by knolleary in post #4 resolved my problem.

Either way - hopefully it will get fed back as an issue to the original project ?

1 Like