simple-xmpp / node-simple-xmpp

Simple High Level NodeJS XMPP Client
300 stars 90 forks source link

'error' event is not emitted when a socket error occurs #19

Open ghost opened 11 years ago

ghost commented 11 years ago

Is this by design? I noticed that socket 'error' events simply call Connection.onEnd(), which quietly exits. I had a case where the socket couldn't connect to the host at all, and my process was quietly finishing looking like everything's fine.

As a work-around, I ended up listening to socket errors directly:

this.xmpp_connection.conn.socket.on 'error',(function(error){
  throw error
}
MiLk commented 11 years ago

http://nodejs.org/api/events.html#events_class_events_eventemitter

When an EventEmitter instance experiences an error, the typical action is to emit an 'error' event. Error events are treated as a special case in node. If there is no listener for it, then the default action is to print a stack trace and exit the program.

Si, it's better to emit an event error, instead of throw an exception.

But, there is already an error event if connection emit an error : https://github.com/arunoda/node-simple-xmpp/blob/master/lib/simple-xmpp.js#L176

Your issue should rather be opened on the node-xmpp repository: https://github.com/astro/node-xmpp/blob/master/lib/xmpp/connection.js#L63