I have a simple node script that uses JSFTP (https://github.com/sergi/jsftp) to make an FTP connection to a server. It's in a test script (using intern) and must detect failures in a graceful way so they are properly reported as a test failure.
When I deliberately corrupt the hostname to which I'm connecting (e.g. serverxxx.com instead of server.com) I find the DNS lookup failure is not handled gracefully.
var ftp = new JSFtp(connDetails);
ftp.auth(someUser, somePass, function (err, res) {
console.log('Auth result: err: ', err, ' res: ', res);
// .. etc
});
I find that the callback is not called ('Auth result:'... is not logged).
I can see in Wireshark the DNS lookup going out and returning 'No such name'. I can trace into the ftp auth call and see that the stream, socket etc have error handlers and they are being called with e.g. ECONNRESET socket level errors, but they deal with closing down the socket and emitting the event 'up' the line (socket, stream, HTTPRequest etc).. nothing seems to feed into the JSFtp object's handler.
I've tried attaching a handler with
ftp.socket.on('error', function (err) { ... }
but it doesn't get called. What's the right thing to do?
Incidentally, I don't have enough point to create a 'jsftp' tag, so cannot tag that.