martynsmith / node-irc

NodeJS IRC client library
GNU General Public License v3.0
1.33k stars 424 forks source link

unhandled/silent connection failure? #459

Open Booster2ooo opened 8 years ago

Booster2ooo commented 8 years ago

Hello,

I noticed there isn't anything happening if you try to connect to a server that doesn't exists. I think it should be handled and emit an error event of some kind.

Here is a sample for you to try:

var irc = require('irc')
  , logger =  function logger() {
        console.log(arguments);
    }
  , instance
  ;

process.on('unhandledRejection', logger);
process.on('uncaughtException',  logger);
try {
    instance = new irc.Client('irc.fake.server', 'myNick', {
        userName: 'username'
      , realName: 'real name'
      , port: 6667
      , autoRejoin: true
      , autoConnect: false
      , channels: []
      , secure: false
      , selfSigned: false
      , certExpired: false
      , stripColors: true
      , encoding: 'UTF-8'
    });
    instance
        .addListener('error', logger)
        .addListener('ping',  logger)
        .addListener('raw',   logger)
        .addListener('close', logger)
        .addListener('quit',  logger)
        .addListener('kill',  logger)
        ;
    instance.connect();
}
catch (ex) {
    logger(ex);
}

Edit: In fact, it emits the undocumented 'netError' event >> https://github.com/martynsmith/node-irc/blob/master/lib/irc.js#L885

thar0x29a commented 7 years ago

Well noticed. The big question ist: Why do we get ECONNREFUSED? I get it the whole time, even thought the server is there and kicking..