Fix for crash when calling whois with non-existant nick #116

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@jazzdev
jazzdev commented Nov 2, 2012

Fix for this crash:

/Users/jd/coffee/node_modules/irc/lib/irc.js:548
throw err;
^
TypeError: Cannot read property 'nick' of undefined
at Client.whois.callbackWrapper (/Users/jd/coffee/node_modules/irc/lib/irc.js:697:22)
at Client.EventEmitter.emit (events.js:88:17)
at Client. (/Users/jd/coffee/node_modules/irc/lib/irc.js:268:22)
at Client.EventEmitter.emit (events.js:88:17)
at Client.connect (/Users/jd/coffee/node_modules/irc/lib/irc.js:545:22)
at Array.forEach (native)
at Socket.Client.connect (/Users/jd/coffee/node_modules/irc/lib/irc.js:542:15)
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:392:31)

@qsheets
Contributor
qsheets commented Nov 3, 2012

Please see README on handling of server error replies. If your client doesn't handle them, node-irc will. And node-irc's way of handling them is to politely crash the program.

@jazzdev
jazzdev commented Nov 3, 2012

Yeah, thanks, I did see that in the ReadMe and I do have an error listener, but the crash still happens.
The error listener gets called to let me know I got a nosuchnick error, but the code then tries to read
a property from an undefined variable and dies.

@qsheets
Contributor
qsheets commented Nov 3, 2012

Do you have a listener for WHOIS in your client as well? I retested it and here is what my client returns on that error:

2 Nov 21:27:55 - SEND: WHOIS qsheets
error:  { prefix: 'adams.freenode.net',
  server: 'adams.freenode.net',
  command: 'err_nosuchnick',
  rawCommand: '401',
  commandType: 'error',
  args: [ 'webuser', 'qsheets', 'No such nick/channel' ] }
2 Nov 21:27:55 - ERROR: { prefix: 'adams.freenode.net',
  server: 'adams.freenode.net',
  command: 'err_nosuchnick',
  rawCommand: '401',
  commandType: 'error',
  args: [ 'webuser', 'qsheets', 'No such nick/channel' ] }
2 Nov 21:27:55 - WHOIS: undefined

It doesn't crash or die.

@jazzdev
jazzdev commented Nov 3, 2012

Ah, that's why it works for you. Setting a listener for whois does not fix it.
But not passing a callback to client.whois() does fix it.

I still think it's a bug. You are allowed to pass a callback to client.whois() and
if you do and the nick name does not exist, you get a crash that your listeners
can't catch.

@martynsmith
Owner

I've just implemented what I think is a nicer solution to this issue.

Instead of altering the callback, I've altered the event such that it will always return an object containing at least the "nick" attribute.

Feel free to re-open this if you continue to have any issues :-)

@jazzdev
jazzdev commented Nov 3, 2012

Yeah, that's an elegant fix. Thanks!

@uiureo uiureo added a commit to uiureo/node-irc that referenced this pull request Feb 2, 2013
@martynsmith @uiureo + uiureo Prevent whois on non-existent nicks from crashing (closes #116) 647e015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment