Hi all,
I'm known for abusing the function nodes without enough knowledge of the VM structure, etc. :).
So, one of the things I do quite a lot is expose 'require' and use raw nodejs modules; it's a lot easier than creating a node-red node when just 'playing' with something.
However, often I find that I get exceptions which I can't catch, e.g. inside a function node, after exposing require through globals:
var require = global.get('require');
var net = require('net');
var fs = require('fs');
var sockname = 'test2.sock';
try{
var path = '/tmp/'+sockname;
var stream = net.connect(path, function(){
stream.write(msg.payload);
node.warn('sent '+msg.payload.length);
stream.end();
});
} catch (e){
node.warn(e);
}
fails like below when the IPC socket is not present:
Oct 26 08:59:32 raspberrypi Node-RED[12773]: 26 Oct 08:59:32 - [red] Uncaught Exception:
Oct 26 08:59:32 raspberrypi Node-RED[12773]: 26 Oct 08:59:32 - Error: connect ENOENT /tmp/test4.sock
Oct 26 08:59:32 raspberrypi Node-RED[12773]: at Object.exports._errnoException (util.js:1020:11)
Oct 26 08:59:32 raspberrypi Node-RED[12773]: at exports._exceptionWithHostPort (util.js:1043:20)
Oct 26 08:59:32 raspberrypi Node-RED[12773]: at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
Oct 26 08:59:33 raspberrypi kernel: [39760.147119] bcm2835-v4l2: error 0 waiting for frame completion
Oct 26 08:59:33 raspberrypi systemd[1]: nodered.service: main process exited, code=exited, status=1/FAILURE
Other exceptions do seem to be 'catchable' from within a function node, some seem to be catchable with the 'catch' node-red node (but not this one).
Is there an easy way to explain what is happening here at the base level?
(I'm not looking at how to avoid the ENOENT; I'm looking for a way to have in not crash when it happens, 'cos the next error is ECONNREFUSED - also uncatchable).
best regards,
Simon
(p.s. the node-opencv bindings are really bad for this; they seem to throw or blow at the slightest error, and it's very rare that I can catch when it does; I give the above example because it's easily reproducible. If you remove the fs.existsSync, then it will except with filenotfound for paths which don't exist).