Note that the catch is empty. If the function throws an exception then this is not caught, and node-red crashes with an uncaught exception. If I replace the catch with
Then the error is logged and node-red does not crash. Is this expected behaviour? I had expected an empty catch to silently swallow the exception. This is using nodejs 22, if that is relevant.
catch is actually a function, expecting a call back as a parameter, so the catch function being called, its self is failing - trying to execute a callback that has not been passed to it
In fact the exception that gets to node red is the original exception, not an error from the invalid catch code. So it appears to be just completely ignoring the catch() statement.
That would imply that the library you are using is not correctly handling its own errors. So that would likely be a bug in the library and something you can raise with the author.
If that library is, itself using a promise and hasn't added a catch, I think that would cause what you are seeing.
Have you tried the await version? Does that behave the same way?
It is that library that I have been debugging. ecowitt-gateway - npm
I have already submitted an issue but I wanted to make sure I understood the problem. It is used by node-red-contrib-ecowitt-gateway and the bug can crash node-red if the gateway is not accessible (or in my case hasn't even been delivered yet, it is coming tomorrow, hopefully).
I find it a bit surprising that an empty catch statement is silently ignored rather than itself raising some sort of error.